js onkeydown 事件 回车 提交表单

<html>
<body>
<script type="text/javascript">
function noNumbers(e)
{
var keynum;
var keychar;
var numcheck;

if(window.event) // IE
	{
	keynum = e.keyCode;
	}
else if(e.which) // Netscape/Firefox/Opera
	{
	keynum = e.which;
	}
keychar = String.fromCharCode(keynum);
alert(keychar)
numcheck = /\d/;
return !numcheck.test(keychar);
}
</script>

<form>
Type some text (numbers not allowed):
<input type="text" onkeydown="return noNumbers(event)" />
</form>

</html>

==================================
//如果输入回车,则提交表单
<input type="text" onkeydown="if(event.keyCode==13)document.forms[0].submit();"/>

你可能感兴趣的:(java,浏览器,IE,Opera,firefox)