回车提交事件,和阻止回车提交
阻止回车提交
<form runat="server" id="form1" onkeypress="javascript:return SAASkeyDown(event)" >
回车提交
<script> function getKeyCode(evt) { if (typeof (evt) == 'string') return evt.charCodeAt(0); return document.all ? event.keyCode : (evt && evt.which) ? evt.which : 0; } function SAASkeyDown(event) { if (getKeyCode(event) == 13) { return false; } } function SearchEnter(event){ if (getKeyCode(event) == 13) { newsSearch(); } } function newsSearch() { var key=document.getElementById("newsSearchKey").value; if(key=="输入关键字") { alert("请输入关键字"); }else { window.location.href="http://search.soufun.com/search?dir=news&q="+escape(key); } } </script> <input type="hidden" name="dir" value="news"> <div class="left kuang"> <input name="q" size="20" type="text" class="kuang" id="newsSearchKey" value="输入关键字" onfocus="if(this.value=='输入关键字')this.value='';" onblur="if(this.value=='')this.value='输入关键字';" onkeydown="SearchEnter(event);"/> </div> <div class="left"> <input type="button" value=" " class="subBut" onclick="newsSearch()"/> </div>
所以我总结了一下,用Javascript提交表单大概有两种写法(根据我目前的理解)
1. document.formName.submit();
2. var form = document.getElementById(id);
http://blog.csdn.net/tohmin/archive/2008/08/01/2752556.aspx
form.submit();
button调用form.submit()方法时不触发onSubmit事件的解决办法(转)
<input type="button" value="test" onclick="if(document.myForm.onsubmit()!=false)document.myForm.submit();">