<!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>无标题文档</title>
<script type="text/javascript">
function checknum(){
var dig,count=0;
var num=document.form1.text3.value;
if(num==""){
alert('请输入数字')
}
else{
for(i=0;i<num.length;i++){
dig=num.charAt(i);
if(dig<'0'||dig>'9'){
alert('输入的必须为数字');
return false;
}
}
}
}function checktext3(){
document.form1.text3.value="";
}
</script><style type="text/css"></style>
</head>
<body>
<form name="form1">
<p>检查是否有数字:
<input type="text" name="text3" value="请输入数字" onclick="checktext3()" />
<input type="button" name="button3" value="检查是否有数字" onclick="checknum()"/>
</p>
</form>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function checknum(){
var dig,count=0;
var num=document.form1.text3.value;
if(num==""){
alert('请输入数字')
}
else{
for(i=0;i<num.length;i++){
dig=num.charAt(i);
if(dig<'0'||dig>'9'){
alert('输入的必须为数字');
return false;
}
}
}
}function checktext3(){
document.form1.text3.value="";
}
</script><style type="text/css"></style>
</head>
<body>
<form name="form1">
<p>检查是否有数字:
<input type="text" name="text3" value="请输入数字" onclick="checktext3()" />
<input type="button" name="button3" value="检查是否有数字" onclick="checknum()"/>
</p>
</form>
</body>
</html>
<form name="form1" onsubmit="return checknum()">
<p>检查是否有数字:
<input type="text" name="text3" value="请输入数字" onclick="checktext3()" />
<input type="button" name="button3" value="检查是否有数字" onclick="checknum()"/>
</p>
</form>