教程集 www.jiaochengji.com
教程集 >  jQuery  >  jquery 教程  >  正文 jQuery选中select控件 无法设置selected的解决方法

jQuery选中select控件 无法设置selected的解决方法

发布时间:2013-08-02   编辑:jiaochengji.com
select 控件的 option用jQuery动态添加,然后选中某项时,IE6不能执行(火狐没问题),用try{}catch(err){alert(err.description);}提示为“无法设置selected属性 未指明的错误”
select 控件的 option用jquery动态添加,然后选中某项时,IE6不能执行(火狐没问题),用try{}catch(err){alert(err.description);}提示为“无法设置selected属性 未指明的错误” 解决办法:把选中option的语句放到setTimeout中,例:
复制代码 代码如下:

setTimeout(function() {
var selSorts = $("select[id^='" + controls.selsort + "']");
$.each(selSorts, function(index, sort) {
var ope = $(sort).find("option[value='" + arrSort[index] + "']");
if (ope.length > 0)
ope[0].selected = true;
});
}, 1);

您可能感兴趣的文章:
jQuery选中select控件 无法设置selected的解决方法
jQuery select操作控制方法小结
Jquery获取Select下拉框中Text与Value的方法详解
jQuery 对Select的操作备忘记录
jquery select选中某个option选项的方法
jQuery获取Select中Text与Value值
jquery下拉select控件操作方法分享(jquery操作select)
JQuery 常用操作代码
jQuery获取Select选择的Text和Value(详细汇总)
jquery 获取表单元素里面的值示例代码

[关闭]
~ ~