IE6 jQuery 操作 select的BUG
来源:互联网 发布:泰罗奥特曼act淘宝 编辑:程序博客网 时间:2024/04/28 21:29
在给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插件之-bgiframe解决ie6下select不被层遮盖的bug
- jquery IE6 select.val() bug报错解决办法
- 解决IE6下select无法设置选中的BUG
- 惊人发现,ie6下的select隐藏有bug
- ie6 select无法被div遮盖的bug解决
- 解决IE6 select无法被div遮盖的bug
- 解决IE6 select z-index无效,遮挡div的bug
- IE6下js通过css隐藏select的一个bug
- 解决jQuery在IE6下遍历XML的Bug!
- jquery treeview插件在ie6上的bug修正
- jquery 选择器 在ie6下的一个bug
- jquery检测ie6的方法(修复了BUG)
- jQuery对select的操作
- 操作select的jquery插件
- jQuery Select的操作集合
- 大型网站架构不得不考虑的10个问题(转)
- Android 视频终端语音控制、按键模拟
- 3维凸包模板
- Javascript图片放大镜
- gcc和g++的区别
- IE6 jQuery 操作 select的BUG
- Linux 的壁纸 在这个目录
- 大型网站架构演变和知识体系
- 凡客的品牌危机
- 详解struct sockaddr
- find与exec ,xargs的组合操作
- MySQL-5.5.25 centos 一键安装脚本 auto install
- 在Swing中创建TreeTable
- db2 使用nickname 访问其它库的表