Javascript 验证ASP.NET客户端中的复选框列表
我试图用下面的代码验证我的复选框列表,但出于某种原因,每次它都会给我错误消息,即使选中了正确数量的复选框,而且我在任何地方都找不到任何sulotion,有人能发现我做错了什么吗Javascript 验证ASP.NET客户端中的复选框列表,javascript,asp.net,validation,Javascript,Asp.net,Validation,我试图用下面的代码验证我的复选框列表,但出于某种原因,每次它都会给我错误消息,即使选中了正确数量的复选框,而且我在任何地方都找不到任何sulotion,有人能发现我做错了什么吗 <asp:CheckBoxList ID="CheckBoxList" runat="server"> </asp:CheckBoxList> <asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidatio
<asp:CheckBoxList ID="CheckBoxList" runat="server">
</asp:CheckBoxList>
<asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="validate" ErrorMessage="choose a role, not more than 2"
ValidationGroup="CreateUserWizard1"></asp:CustomValidator>
<script type="text/javascript">
function validate(source, arguments) {
arguments.IsValid = false;
var checklist = document.getElementById("CheckBoxList");
if (checklist == null) return;
var elements = checklist.getElementsByTagName("INPUT");
if (elements == null) return;
var checkBoxCount = 0;
for (i = 0; i < elements.length; i++) {
if (elements[i].checked) checkBoxCount++;
}
arguments.IsValid = (checkBoxCount > 0 || checkBoxCount <= 2);
}
</script>
函数验证(源、参数){
arguments.IsValid=false;
var checklist=document.getElementById(“CheckBoxList”);
如果(检查表==null)返回;
变量元素=checklist.getElementsByTagName(“输入”);
if(elements==null)返回;
var checkBoxCount=0;
对于(i=0;i arguments.IsValid=(checkBoxCount>0 | | checkBoxCount必须获取复选框的呈现id,如下所示:
var checklist=document.getElementById(“”;
你也可以阅读: