我想編寫一個程序,所以我可以輸入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」)'。 –