我有一个 javascript 函数,其中基于选择我必须启用一行并禁用同一页面上的按钮。早些时候,它是通过后面的代码处理的,并且使用相同的逻辑可以正常工作。现在它不起作用。
JS函数:
function ValidateRadioButtonList()
{
var RBL = document.getElementById('<%=rbListExamShot.ClientID%>');
var radiobuttonlist = RBL.getElementsByTagName("input");
var counter = 0;
var atLeast = 1
for (var i = 0; i < radiobuttonlist.length; i++) {
if (radiobuttonlist[i].checked) {
counter++;
var selected = i;
}
}
if (atLeast = counter) {
// return arguments.IsValid;
var RowMessage = document.getElementById ('<% =RowCliamMessage.ClientID%>');
RowMessage.style.display = "block";
}
else {
RowMessage.style.display = "none";
}
if (selected == 1) {
var Submit = document.getElementById('<%=Save.ClientID%>');
Submit.disabled = true;
return false;
}
else {
return true;
}
}
asp.net 控制和验证器:
<td align="left">
<asp:RadioButtonList CssClass="label" ID="rbListExamShot" runat="server" AutoPostBack="true"
RepeatDirection="Horizontal" ValidationGroup="Save"
onselectedindexchanged="rbListExamShot_SelectedIndexChanged">
<asp:ListItem Text="Single Shot" Value="1"></asp:ListItem>
<asp:ListItem Text="Double Shot" Value="2"></asp:ListItem>
</asp:RadioButtonList>
</td>
<td>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Text="Please select voucher type"
Display="Dynamic" ControlToValidate="rbListExamShot" ValidationGroup="Save"
ForeColor="Red" Font-Bold="False"></asp:RequiredFieldValidator>
<asp:CustomValidator ID="CustomValidator1" runat="server" ValidationGroup="Save"
Display="Dynamic" ErrorMessage=".Double Shot Vouchers cannot be reimbursed."
ControlToValidate="rbListExamShot" ClientValidationFunction="ValidateRadioButtonList"
ForeColor="Red" Font-Bold="False"></asp:CustomValidator>
</td>