dsf22567 2009-06-08 12:42
浏览 8
已采纳

点击“输入”不会在IE8中发布表单

I'm using PHP to pass a login form when required, and here is the code:

$htmlForm = '<form id="frmlogin">'.'<label>';
switch(LOGIN_METHOD)
{
    case 'both':
        $htmlForm .= $ACL_LANG['USERNAME'].'/'.$ACL_LANG['EMAIL'];
        break;
    case 'email':
        $htmlForm .= $ACL_LANG['EMAIL'];
        break;
    default:
        $htmlForm .= $ACL_LANG['USERNAME'];
        break;
}                       

$htmlForm .= ':</label>'.
             '<input type="text" name="u" id="u" class="textfield" />'.
             '<label>'.$ACL_LANG['PASSWORD'].'</label>'.
             '<input type="password" name="p" id="p" class="textfield" />'.
             '<center><input type="submit" name="btn" id="btn" class="buttonfield" value="Sign in to extranet" /></center>'.
             '</form>';

return $htmlForm;

The problem is, is that when the user hits enter in IE8, the form does not submit, and the user is forced to hit the submit button.

How do I rectify this?

  • 写回答

7条回答 默认 最新

  • dpbyr64224 2009-06-08 12:57
    关注

    If this is a real problem and you can't find another solution you can always do an onkeypress event for the form and check if the <kbd>Enter</kbd> key was pressed.

    EDIT: Here's the correct code according to Machine's answer:

    $htmlForm .= ':<form><label>'.$ACL_LANG['USERNAME'].'</label>'.
                                         '<input type="text" name="u" id="u" class="textfield" />'.
                                         '<label>'.$ACL_LANG['PASSWORD'].'</label>'.
                                         '<input type="password" name="p" id="p" class="textfield" />'.
                                         '<center><input type="submit" name="btn" id="btn" class="buttonfield" value="Sign in to extranet" /></center>'.
                                         '</form>';
    

    EDIT 2: Your HTML is valid. Try this:

    function checkEnter(e) { //e is event object passed from function invocation
        var characterCode //literal character code will be stored in this variable
    
        if (e && e.which) { //if which property of event object is supported (NN4)
            e = e
            characterCode = e.which //character code is contained in NN4's which property
        }
        else {
            e = event
            characterCode = e.keyCode //character code is contained in IE's keyCode property
        }
    
        if (characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key)
            document.forms[0].submit() //submit the form
            return false
        }
        else {
            return true
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100