我想使用
jquery禁用下拉列表项.
索引值为-1,值为——-内部——-.我一个接一个地尝试了以下语法(解决方案是类似问题的答案).他们都没有工作.我使用的是IE8.
索引值为-1,值为——-内部——-.我一个接一个地尝试了以下语法(解决方案是类似问题的答案).他们都没有工作.我使用的是IE8.
var value="------- Internal -------"; $("[id*='ChildOrganizationDropDownList'] option[value=" + value + "]").prop('disabled','disabled'); $("#ChildOrganizationDropDownList option[value=" + value + "]").prop('disabled','disabled'); $("[id*='ChildOrganizationDropDownList']").option('------- Internal -------').prop('disabled',true); $("id*='ChildOrganizationDropDownList' option[value='------- Internal -------']").prop('disabled','disabled'); $("[id*='ChildOrganizationDropDownList']").option("[value*='------- Internal -------']").prop('disabled',true); $("[id*='ChildOrganizationDropDownList']").attr("disabled",$(_this.CustomerNameDropDownList).find("option[value='------- Internal -------']"));
设计师:Aspx
<div class="selectionControls"> <asp:CheckBox ID="chkSubcontracting" runat="server" Text="Subcontracting" Enabled="true" /> <asp:HiddenField ID="SubcontractingHiddenField" runat="server" /> <div class="subSelectionControl" id="AllowSubcotractingSelection" style="display: none;"> <div class="subContractingControls"> Parent BU: <span> <div class="subContractingControls"> Supplier <em class="mandatoryIndicator">*</em>: <span> <asp:DropDownList ID="ChildOrganizationDropDownList" runat="server" Width="200px" /> <asp:HiddenField ID="IxChildOrganizationHiddenField" runat="server" /> </span> </div> </div> </div>
Aspx.cs
public Dictionary<int,string> ChildOrganizations { set { var result = value; result.Add(0,"Select Supplier"); ChildOrganizationDropDownList.DataSource = result; ChildOrganizationDropDownList.DataTextField = "value"; ChildOrganizationDropDownList.DataValueField = "key"; ChildOrganizationDropDownList.DataBind(); ChildOrganizationDropDownList.SelectedValue = "0"; } }
解决方法
我用过它们,它对我有用:
https://jsfiddle.net/pz9curkb/1/
<select id="ChildOrganizationDropDownList"> <option value="Default">Default</option> <option value="A">A</option> <option value="B">------- Internal -------</option> <option value="E">E</option> </select> $("#ChildOrganizationDropDownList option").each(function(){ if($(this).text() === "------- Internal -------"){ this.disabled = true; } });
请注意在此解决方案中我使用此而不是$(this),这意味着我使用了javascript提供的禁用选项