扫码关注官方订阅号
总是提示错误,可能是因为document.all后面的选项中多了一些分号,那如何改进呢?谢谢
走同样的路,发现不同的人生
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 { }
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
就改成了if(){}就对了,也没细看。
改进的话当然是能力检测了