如何用js屏蔽按回车提交表单
如何用js屏蔽按回车提交表单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>test</title> <script language="JavaScript"> <!-- var $=function(sId){return document.getElementById(sId);}; function chkform(formId) { if (formId.myname.value=="") { alert("名字 不能为空"); return false; } return true; } function chkchk(e) { if (e.keyCode==13) { alert(e.keyCode); return false; } return true; } //--> </script></head><body><form name="adform" action="save.asp" method="post" onkeydown="javascript:return chkchk(event);" onsubmit="javascript:return chkform(this);">名字:<input type="text" name="myname" value="" /><br/><input type="submit" name="submitbtn" value="提交" /></form></body></html>function chkchk(e){ if(window.event) { if (e.keyCode==13) { alert(e.keyCode); return false; } return true; } else { if (e.which==13) { e.preventDefault(); return false; } return true; }}
[解决办法]
测试通过
[解决办法]
把js里面的那个HTML注释删除