日期:2014-05-16 浏览次数:20456 次
<script type="text/javascript">
function validate(){
var num = document.getElementsByName("number")[0];
if(num.value.length < 1){
alert("请输入数字");
num.focus();
return false;
}
var param="0123456789";
for(var i = 0; i<num.value.length;i++){
if(param.indexOf(num.value.charAt(i))==-1){
alert("输入必须为数字");
num.focus();
return false;
}
}
if(parseInt(num.value) < 5 || parseInt(num.value) >15 ){
num.value = 10;
}
return true;
}
</script>
?
<form aciton="#" name="form1" method="post" onsubmit="return validate();">
请输入数字(5-15):<input type="text" name="number"/><br>
<input type="submit" value="提交"/>
</form>