<script language="javascript">
function CheckMyForm()
{
var txt = myform.mytext.value;
if(checknumber(txt))
{
alert("不是数字!");
return false;
}
alert("你输入的是数字!");
return true;
}
function checknumber(String)
{
var Letters = "1234567890";
var i;
var c;
for( i = 0; i < String.length; i ++ )
{
c = String.charAt( i );
if (Letters.indexOf( c ) ==-1)
{
return true;
}
}
return false;
}
</script>
<body >
<form name="myform" onSubmit="return CheckMyForm()">
<input type="text" name="mytext">
<input type="submit" name="mysubmit">
<br><br>
<input type="text" name="textbox" onKeydown="javascript:if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false; else alert(event.keyCode);"> 过滤键盘输入,只有数字按键是有效的输入。
</form>
</body>