<html>
<body>
<input id="input" name="txt" onKeyUp="check(this.value)"/>
</body>
</html>
<script language="javascript">
function check(value)
{
//限制只能输入数字
if(value.replace(/[/d+]/ig,"").length>0)
{
alert("只能输入数字!");
}
}
</script>