为什么这段代码不起作用:
jquery的:
$("input[id$='rbtlDestination']").change(function(){
if ($(this).val() == "To Subsidiary:")
$("input[id$='ddlSubsidiaries']").removeAttr('disabled');
else
$("input[id$='ddlSubsidiaries']").attr('disabled', 'disabled');
});
HTML:
<asp:RadioButtonList ID="rbtlDestination" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" CssClass="FormatRadioButtonListItems">
<asp:ListItem Selected="True" Value="To Work">To Work</asp:ListItem>
<asp:ListItem Value="To Subsidiary:">To Subsidiary:</asp:ListItem>
</asp:RadioButtonList>
<asp:DropDownList ID="ddlSubsidiaries" runat="server" Width="160px" Enabled="false"
DataSourceID="odsSubsidiaries" DataTextField="Subsidiary"
DataValueField="IdSubsidiary">
</asp:DropDownList>
渲染:
<span id="ctl00_ContentPlaceHolder1_rbtlDestination" class="FormatRadioButtonListItems">
<input id="ctl00_ContentPlaceHolder1_rbtlDestination_0" type="radio" name="ctl00$ContentPlaceHolder1$rbtlDestination" value="To Work" checked="checked" />
<label for="ctl00_ContentPlaceHolder1_rbtlDestination_0">To Work</label>
<input id="ctl00_ContentPlaceHolder1_rbtlDestination_1" type="radio" name="ctl00$ContentPlaceHolder1$rbtlDestination" value="To Subsidiary:" />
<label for="ctl00_ContentPlaceHolder1_rbtlDestination_1">To Subsidiary:</label></span>
<select name="ctl00$ContentPlaceHolder1$ddlSubsidiaries" id="ctl00_ContentPlaceHolder1_ddlSubsidiaries" disabled="disabled" style="width:160px;">
<option selected="selected" value="2">Sub A</option>
<option value="1">Sub B</option>
答案 0 :(得分:2)
试试这个,
<强>的Javascript 强>
$(document).ready(function () {
$(".FormatRadioButtonListItems input[type=radio]").change(function () {
if ($(this).val() == "To Subsidiary:")
$(".ddlSubsidiaries").prop("disabled", false)
else
$(".ddlSubsidiaries").prop("disabled", true)
});
});
<强> Asp.net 强>
<asp:RadioButtonList ID="rbtlDestination" runat="server" RepeatDirection="Horizontal" RepeatLayout="Flow" CssClass="FormatRadioButtonListItems">
<asp:ListItem Selected="True" Value="To Work">To Work</asp:ListItem>
<asp:ListItem Value="To Subsidiary:">To Subsidiary:</asp:ListItem>
</asp:RadioButtonList>
<asp:DropDownList ID="ddlSubsidiaries" runat="server" Width="160px" Enabled="false"
DataSourceID="odsSubsidiaries" DataTextField="Subsidiary"
DataValueField="IdSubsidiary" CssClass="ddlSubsidiaries">
</asp:DropDownList>