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 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用