<html>
<head>
<title>测试数字</title>
<script>
function onCheck(){
var numValue=document.getElementById("num").value;
var index=-1;
for(var i=0;i<numValue.length;i++){
var ch=numValue.charAt(i);
if(ch>=0&&ch<=9){
index=-1;
}else{
index=1;
break;
}
}
if(index==1){
alert("您输入的非数字!请重新输入");
document.getElementById("num").value="";
return;
}else{
alert("输入正确!您输入的数字是:"+numValue);
}
}
function onCheck1(){
var numValue=document.getElementById("num1").value;
if(isNaN(numValue)){
alert("您输入的非数字!请重新输入...");
document.getElementById("num1").value="";
return;
}else{
alert("输入正确!您输入的数字是:"+numValue);
}
}
</script>
</head>
<body>
<h3>测试输入是否是数字第一种方法</h3>
<input type="text" id="num" />
<input type="button" value="测试1" onclick="onCheck()" />
<h3>测试输入是否是数字第二种方法</h3>
<input type="text" id="num1" />
<input type="button" value="测试2" onclick="onCheck1()" />
</body>
</html>
?