87,910
社区成员
发帖
与我相关
我的任务
分享
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="text" name="zb" id="aa" onblur="gg(this)">
<input type="text" name="yb" id="bb" onblur="gg(this)">
<script>
function gg(_this){
if(isNaN(_this.value)){
alert("不是数字");
_this.value = "";
_this.focus();
}else if(_this.value!=""){
alert("是数字");
return false;
}
}
</script>
</body>
</html>
[].forEach.call(document.querySelectorAll("#aa,#bb"),function($dom){
$dom.onblur = function(){
if (isNaN(this.value)) {
alert("不是数字");
this.value = "";
this.focus();
} else if (this.value != "") {
alert("是数字");
return false;
}
}
});