1

我有一个页面,当按下回车键时我有一个文本框,它将调用这个 javascript 来提交表单。我设置的表格是这样的。所以我注意到当我第一次在 chrome 中按 Enter 时,它会通过 post 发送数据。第二次是通过get发送。我可以通过检查元素看到它。但在 IE 和 FF 中工作得非常好。

 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
    }
    //alert("Check Enter : "+characterCode);

    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 
    }
}
4

0 回答 0