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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值