我有一个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>
答案 0 :(得分:1)
感谢大家的评论..问题是我在var中获取客户端ID,然后尝试设置属性..现在我正在做类似的事情:document.getElementById('&lt;%= Save.ClientID% &gt;')。disabled = true ..这对我有用!谢谢所有
答案 1 :(得分:-1)
<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>