ITeye博客

jquery 在IE6中设置select控件的selected属性的时候

fuanyu · 2011-02-22 10:50 · js · Web前端 · 浏览器 · jQuery · Firefox · Markdown

在IE6中使用jquery给select 赋值选中某值时会出现如下错误:

赋值语句:

$("#selectID").val("xx");
$("#selectID option").attr("selected",true);
$("#selectID option[value='xx']").attr("selected",true);

在IE7,IE8,IE5.5及Firefox等浏览器下面没有问题

有人找到了一个解决的方法,就是设置selected属性的时候使用setTimeout函数 设定一个时间 即可,代码如下:

// 使用setTimeout之后问题解决 

setTimeout(function() { 
    $("#selectID option").attr("selected",true);

    $("#selectID option[value='xx']").attr("selected",true);
}, 1);

而我的解决方法是

  setTimeout(function() {
             $("#areaCode").val("<s:property value='school.areaCode'/>");  //进行selected选中
            });

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。