禁用下拉列表项jquery无法正常工作

Man*_*yak 8 asp.net jquery

我想使用jquery禁用下拉列表项.索引值为-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 -------']"));
Run Code Online (Sandbox Code Playgroud)

设计师: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>
Run Code Online (Sandbox Code Playgroud)

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";


            }
        }
Run Code Online (Sandbox Code Playgroud)

ren*_*kre 3

我使用过each并且它对我有用: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;
     }
});
Run Code Online (Sandbox Code Playgroud)

请注意,在此解决方案中,我使用了 this 而不是 $(this),这意味着我使用了 javascript 提供的禁用选项