(南师大现代教育技术15年编程题)
①完善checkinput()部分的代码;②在第23行的空白处填上适当的内容。
checkInput()部分的代码功能是:
对表单中输入的数据进行检验。如果用户输入了纯数字[0-9]数据,则校验通过;否则提示用户输入数据或更改数据,并终止提交,同时将光标定位于输入文本框中。
注意:onsubmit后面的引号中写return oncheckInput()才可以,否则不论是否返回true都会跳转action。
附:如果想要加载页面时就获取鼠标指针在第一个input,需要:
window.onload=function(){
num[0].select();
}
<!DOCTYPE HTML>
<html>
<head>
<title> 15-1 </title>
</head>
<body>
<script>
var num = document.getElementsByName("inputContent");
function oncheckInput(){
if(num[0].value<10 & num[0].value>=0){
alert("通过");
}else{
alert("请检查");
num[0].select();
return false;
}
return true;
}
</script>
<form id="form1" name="myform" method="POST" action="#" onsubmit="return oncheckInput()">
<label>请输入内容</label>
<input type="text" name="inputContent" maxlength="24"/>
<br>
<input type="submit" name="submit" value="提交"/>
</form>
</body>
</html>