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

前端之家收集整理的这篇文章主要介绍了禁用下拉列表项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 -------']"));

设计师: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提供的禁用选项

原文链接:https://www.f2er.com/jquery/178669.html

猜你在找的jQuery相关文章