IE6 jQuery 操作 select的BUG
2012-10-12 14:04
369 查看
在给select初始化的时候,除了ie 6外的所有浏览器中都正常显示效果(ie7,8,9,
firefox, chrome), IE6下提示“无法设置selected属性,未指明的错误”或者就是根本就没有显示。
后来找了找资料发现是jquery在ie6下操作select控件有BUG .$("#hour_").val(2);
改成:
setTimeout(function(){
$("#hour_").val(2);
},1);
就可以了.
原因是:
Note that the error will only occur if you call appendChild , then
ask for the select 's childNodes , then set the selected property
on the newly created option . If you set selected earlier, either before appendChild or
after it, there's no problem. And if you omit childNodes , it works. The problem with jQuery is that its .val() function
loops over childNodes looking for an option to set, and thus always triggers the bug.
最后可以定义个函数set_select_val来统一设置select控件的值
function set_select_val(sel, val)
{
if($.browser.msie && $.browser.version=="6.0") {
setTimeout(function(){
sel.val(val);
},1);
}else {
sel .val(val);
}
}
set_select_val($("#hour"),'2');
相关文章推荐
- IE6 下 jQuery 操作 select的BUG
- IE6 下 jQuery 操作 select的BUG
- IE6 下 jQuery 操作 select的BUG
- jquery IE6 select.val() bug报错解决办法
- JQuery操作Select的Options的Bug(IE8兼容性视图模式)
- jquery IE6 select.val() bug报错解决办法
- JQuery在IE8兼容性视图模式下操作Select的Options的Bug
- jquery IE6 select.val() bug报错解决办法
- jQuery插件之-bgiframe解决ie6下select不被层遮盖的bug
- IE6下jQuery选中select的BUG
- IE6使用jquery.bgiframe.js解决select元素不会正常隐藏的BUG
- jquery select option操作
- jquery对select进行种各种操作的方法[联动、根据值或文本选中指定的select等]
- jquery操作select(取值,设置选中)
- jquery对select下拉框的一些基本操作
- jquery对select操作
- jQuery系列之操作select标签
- jquery 的$(document).ready 在IE6下图片不缓存的bug解决;
- “checkbox”和“select”对象在javascript和jquery的操作差异做了整理