总是提示错误,可能是因为document.all后面的选项中多了一些分号,那如何改进呢?谢谢
1 回答
慕容3067478
TA贡献1773条经验 获得超3个赞
function input_defaultValue() { var get_input = document.getElementsByTagName("input"); for(var i = 0; i < get_input.length; i++) { if(document.all) {
get_input[i].attachEvent('onfocus', function() { if(this.value == this.defaultValue) { this.value = '';
}
});
get_input[i].attachEvent('onblur', function() { if(this.value == '') { this.value = this.defaultValue;
}
});
} else {
get_input[i].addEventListener('focus', function() { if(this.value == this.defaultValue) { this.value = '';
}
});
get_input[i].addEventListener('blur', function() { if(this.value == '') { this.value = this.defaultValue;
}
});
};
}
};
input_defaultValue();就改成了if(){}就对了,也没细看。
改进的话当然是能力检测了
if(document.addEventListener) { //
} else if(document.attachEvent()) { //
} else {
}添加回答
举报
0/150
提交
取消
