日期:2014-05-16  浏览次数:20380 次

[20 分] 如何让 HTML 下的 TextBox 控件在按下回车时不会提交表单?
有两个   TextBox,第一个当   Focus()   时按回车不会提交:

<input   name= "facs "   type= "text "   id= "facs "   style= "ime-mode:Disabled;   "   size=33   maxlength=50  
    onKeyPress= "return   regInput(this,/^[0-9   ()-]*$/,String.fromCharCode(event.keyCode)) "  
    onpaste= "return   regInput(this,/^[0-9   ()-]*$/,window.clipboardData.getData( 'Text ')) "  
    ondrop= "regInput(this,/^[0-9   ()-]*$/,event.dataTransfer.getData( 'Text ')) ">

但是第二个会自动提交:

<input   name= "address "   type= "text "   id= "address "   style= "ime-mode:Disabled; "   size=50   maxlength=256  
    onKeyPress= "return   regInput(this,/^[\000-\255]*$/,String.fromCharCode(event.keyCode)) "  
    onpaste= "return   regInput(this,/^[\000-\255]*$/,window.clipboardData.getData( 'Text ')) "  
    ondrop= "regInput(this,/^[\000-\255]*$/,event.dataTransfer.getData( 'Text ')) "   >

请问,如何让第二个在Focus()时,按下回车也不会提交?

------解决方案--------------------
<script language= "javascript " event= "onkeydown " for= "document ">

if ( event.keyCode == 13 )
{
// 将 Enter 键 设置为 Tab 键
event.keyCode = 9;

// Enter 键 不提交页面。
//event.returnValue = false
}
</script>

以上代码放到 head 里就可以了。