我想编写一个程序,所以我可以输入0到255之间的IP地址编号。 但是这个程序在IE中运行良好,但是在firefox和chrome中没有。 有没有问题?谢谢。JavaScript程序在IE中运行良好,但不适用于Firefox和Chrome。填写IP地址
我刚刚发现它在这里也不起作用。
function check(obj) {
var txt = obj.getAttribute("value");
txt = parseInt(txt);
if (txt > 255 || txt < 0) {
alert("must between 0 and 255");
obj.focus();
obj.select();
} else {
if (txt > 25) {
var next = parseInt(obj.getAttribute("id")) + 1;
if (next < 5) {
document.getElementById(next.toString()).focus();
}
}
}
}
<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);" />
看起来像一个IE浏览器的bug(因为它不应该在那里工作要么) - 我相信'OBJ .getAttribute(“value”);'_应该给出属性的原始值,而不是当前输入的值。 –
什么“不起作用”?你能解释一下你的问题吗? – Frxstrem
例如,您应该使用'obj.value',而不是'obj.getAttribute(“value”)'。 –