javascript onkeyup 写了一个类似ip地址填写的框,ie完美运行,firefox, chrome, 遨游都不行,是出了什么问题呢?
<!DOCTYPE html>
<html>
<head>
<title>js14.html</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function check(obj){
var txt = obj.getAttribute("value");
txt = parseInt(txt);
if(txt>255||txt<0){
alert("数字必须在0到255之间");
obj.focus();
obj.select();
}else{
if(txt>25){
var next = parseInt(obj.getAttribute("id"))+1;
if(next<5){
document.getElementById(next.toString()).focus();
}
}
}
}
</script>
</head>
<body>
<input type="text" maxlength="3" id="1" onkeyup="check(this);" />
<input type="text" maxlength="3" id="2" onkeyup="check(this);"/>
<input type="text" maxlength="3" id="3" onkeyup="check(this);"/>
<input type="text" maxlength="3" id="4" onkeyup="check(this);"/>
</body>
</html>