`
virtual_function
  • 浏览: 127612 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

IE6中 “无法设置selected属性”的脚本错误提示

阅读更多


在IE6下,弹出脚本错误的提示:无法设置selected属性 未指明的错误

代码:selectObj.val(defaultSelect);//选中指定项

出现场景:动态填充select标签:为其添加option选项,之后设置默认项时出现
后期测试:发现并不一定出现,非常怪异,应该是还没有完全明白发生这个问题的时机

解决办法:

在设置selected属性的时候使用setTimeout函数设定一个任意时间即可
setTimeout(function(){
     selectObj.val(defaultSelect);//选中指定项
},0);

IE 6 can throw an error "Error: Could not set the selected property. Unspecified error." when you try to manipulate select elements by adding options and then selecting one of your newly created items. I came across this while trying to use jQuery's .val() function to set the selected element after I had added some options to my select.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics