gpt4 book ai didi

jquery - removeAttr ("selected") 在 IE6 中显示错误

转载 作者:行者123 更新时间:2023-12-01 01:39:20 25 4
gpt4 key购买 nike

我有两个列表框设置了多个属性,并且在将项目从第一个添加到第二个时,我不希望在第二个列表框中进行选择。

我写的代码是这样的

$("#<%=lbCommcatTo.ClientID%> option").removeAttr("selected");

它在 IE7 中有效,但在 IE6 中无效。谁能给我一个解决方案吗?

html 是

<table cellspacing="0" cellpadding="0" width="100%" border="0">
<tr>
<td width="45%">
<div style="height: 230px;width: 234px; overflow: auto; border: solid 1px #c1c1c1" id="dvLeft" runat="server">
<select id="lbCommcatFrom" runat="server" style="height:790px;" multiple name="lbCommcatFrom" class="ContentTextNormal">
</select>
</div>
</td>
<td width="10%" align="center">
<div style="border: solid 1px #6E6E6E; width: 20px; height: 20px; padding-top: 4px; text-align: center; margin-bottom: 5px; background-color: #CECFBE; cursor: pointer" title="Add to List" id="imgMoveRight" class="clsArrow">
</div>
<div style="border: solid 1px #6E6E6E; width: 20px; height: 20px; padding-top: 4px; text-align: center; background-color: #CECFBE; cursor: default" title="Remove from List" id="imgMoveLeft" class="clsArrow">
</div>
</td>
<td width="45%">
<div style="height: 230px;width: 234px; overflow: auto; border: solid 1px #c1c1c1" id="dvRight" runat="server">
<select id="lbCommcatTo" runat="server" style="height:230px;width:234px" multiple name="lbCommcatTo" class="ContentTextNormal">
</select>
</div>
</td>
</tr>
</table>

脚本是这样的

$("#imgMoveRight").click(function(){   
$("#<%=lbCommcatFrom.ClientID%> option:selected").appendTo("#<%=lbCommcatTo.ClientID%>");

if( $("#<%=lbCommcatFrom.ClientID%> option").length == 0)
{
$("#<%=lbCommcatFrom.ClientID%>").parent().css("overflow-x","hidden");
$("#<%=lbCommcatFrom.ClientID%>").parent().css("overflow-y","hidden");
$("#<%=lbCommcatFrom.ClientID%>").css("width","234px");
$("#<%=lbCommcatFrom.ClientID%>").css("height","230px");
$(this).css("cursor","default");
}
else
{
if($("#<%=lbCommcatTo.ClientID%> option").length > 0)
{
$("#<%=lbCommcatTo.ClientID%>").parent().css("overflow-x","scroll");
$("#<%=lbCommcatTo.ClientID%>").css("width","465");
$("#<%=lbCommcatFrom.ClientID%>").css("width","465");
if($("#<%=lbCommcatTo.ClientID%> option").length > 15)
{
$("#<%=lbCommcatTo.ClientID%>").css("height",$("#<%=lbCommcatTo.ClientID%> option").length * 18);
$("#<%=lbCommcatTo.ClientID%>").parent().css("overflow-y","scroll");
}
else
{
$("#<%=lbCommcatTo.ClientID%>").css("height","230");
$("#<%=lbCommcatTo.ClientID%>").parent().css("overflow-y","hidden");
}

$("#imgMoveLeft").css("cursor","pointer");
}
}
**$("#<%=lbCommcatTo.ClientID%> option").removeAttr("selected");**



});

$("#imgMoveLeft").click(function(){

$("#<%=lbCommcatTo.ClientID%> option:selected").appendTo("#<%=lbCommcatFrom.ClientID%>");
$("#<%=lbCommcatFrom.ClientID%>").css("width","465");
if( $("#<%=lbCommcatTo.ClientID%> option").length == 0)
{
$("#<%=lbCommcatFrom.ClientID%>").parent().css("overflow","scroll");
$("#<%=lbCommcatTo.ClientID%>").parent().css("overflow-x","hidden");
$("#<%=lbCommcatTo.ClientID%>").parent().css("overflow-y","hidden");
$("#<%=lbCommcatTo.ClientID%>").css("width","232px");
$("#<%=lbCommcatTo.ClientID%>").css("height","230px");
$(this).css("cursor","default");
}
else
{
if($("#<%=lbCommcatFrom.ClientID%> option").length > 0)
{
$("#<%=lbCommcatFrom.ClientID%>").parent().css("overflow-x","scroll");
if($("#<%=lbCommcatFrom.ClientID%> option").length > 15)
{
$("#<%=lbCommcatFrom.ClientID%>").css("height",$("#<%=lbCommcatFrom.ClientID%> option").length * 16);
$("#<%=lbCommcatFrom.ClientID%>").parent().css("overflow-y","scroll");
}
else
{
$("#<%=lbCommcatFrom.ClientID%>").css("height","230");
$("#<%=lbCommcatFrom.ClientID%>").parent().css("overflow-y","hidden");
}
$("#imgMoveRight").css("cursor","pointer");
}
}

**$("#<%=lbCommcatFrom.ClientID%> option").removeAttr("selected");**
});

最佳答案

您可以尝试使用“attr”

$("#<%=lbCommcatTo.ClientID%> option").attr("selected", "");

[Source ]

看看这里:[ Link ] 更具体地说:

If you wrap the code that sets selected in a setTimeout it works, surprisingly enough.
I have to assume it needs to give control back to the browser to let state settle.

Another way to get this to work is to wrap the code that sets selected in a try/catch
block and just swallow the error from IE. It seems to set the element as selected properly
despite the error!

关于jquery - removeAttr ("selected") 在 IE6 中显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4012649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com