当 ASP.Net RadioButtonList 的选定值发生更改时,我想使用 jQuery 事件处理程序运行一些 Javascript 代码;具体来说,我想在 TextBox 上启用/禁用 RequiredFieldValidator(取决于 RadioButtonList 的选定值)。但是当我单击 RadioButtonList 中的一项(更改其值)时,什么也没有发生。
这是Javascript代码:
var rbAuth = "<%= rbServiceHours.ClientID %>";
var vRespName = "<%= vRespNameReq.ClientID %>";
var vRespTitle = "<%= vRespTitleReq.ClientID %>";
var tbxRespName = "<%= tbxRespName.ClientID %>";
var tbxRespTitle = "<%= tbxRespTitle.ClientID %>";
$('#' + rbAuth + " > input").click(function () {
if (($('#' + rbAuth).find('input:checked').val()) == 'Yes') {
$('#' + vRespName).attr('enabled', 'true');
$('#' + vRespTitle).attr('enabled', 'true');
$('#' + tbxRespName).addClass("required");
$('#' + tbxRespTitle).addClass("required");
}
else {
$('#' + vRespName).attr('enabled', 'false');
$('#' + vRespTitle).attr('enabled', 'false');
$('#' + tbxRespName).removeClass("required");
$('#' + tbxRespTitle).removeClass("required");
}
});
这当然是在里面$(document).ready( function() {});
这是相应的 ASP.Net 标记:
<asp:RadioButtonList ID="rbServiceHours" runat="server" RepeatDirection="Horizontal"
CssClass="required" ValidationGroup="valIncident" TabIndex="31">
<asp:ListItem Value="Y" Text="Yes"></asp:ListItem>
<asp:ListItem Value="N" Text="No"></asp:ListItem>
</asp:RadioButtonList>
<asp:TextBox ID="tbxRespName" runat="server" MaxLength="50" TabIndex="29">
</asp:TextBox>
<asp:RequiredFieldValidator ID="vRespNameReq" runat="server" ErrorMessage="<br />Please enter the caregiver's name."
CssClass="validationError" ControlToValidate="tbxRespName" ForeColor="White"
BackColor="Red" SetFocusOnError="true" ValidationGroup="valIncident"
Display="Dynamic"></asp:RequiredFieldValidator>
<asp:TextBox ID="tbxRespTitle" runat="server" MaxLength="50" TabIndex="29">
</asp:TextBox>
<asp:RequiredFieldValidator ID="vRespTitleReq" runat="server" ErrorMessage="<br />Please enter the caregiver's title."
CssClass="validationError" ControlToValidate="tbxRespTitle" ForeColor="White"
BackColor="Red" SetFocusOnError="true" ValidationGroup="valIncident" Display="Dynamic"></asp:RequiredFieldValidator>
谁能指出我正确的方向?谢谢!
编辑:这是呈现的 HTML:
<input name="ctl00$MainContent$tbxRespName" type="text" maxlength="50"
id="ctl00_MainContent_tbxRespName" tabindex="29" />
<span id="ctl00_MainContent_vRespNameReq" class="validationError"
style="color:White;background-color:Red;display:none;"><br />Please enter the
caregiver's name.</span>
<input name="ctl00$MainContent$tbxRespTitle" type="text" maxlength="50"
id="ctl00_MainContent_tbxRespTitle" tabindex="30" /><br />
<span id="ctl00_MainContent_vRespTitleReq" class="validationError"
style="color:White;background-color:Red;display:none;"><br />Please enter the
caregiver's title.</span>