日期:2014-05-18  浏览次数:20606 次

请问这个js验证错在哪?
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DiaoChaInfo.aspx.cs" Inherits="DiaoChaInfo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
  <script type="text/javascript" language="javascript">
  function checkreg() {
  j = 0;
  for (i = 0; i < document.form1.Repeater1.RadioButtonList1.length; i++) {
  if (document.form1.Repeater1.RadioButtonList1.checked == true) {
  j++;
  }
  }
  if (j == 0) {
  alert('请选择');
  return false;
  }
  return true
  } 
  </script>
</head>
<body>
  <form id="form1" runat="server" onsubmit="return checkreg()">
  <div>
  <div>
  <asp:Label ID="DiaoChaTitle" runat="server" Text=""></asp:Label></div>
  <div>
  <asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
  <ItemTemplate>
  <asp:HiddenField ID="HiddenField1" runat="server" Value='<%#Eval("timuID")%>' />
  <%#Eval("timuName")%>
  <asp:RadioButtonList ID="RadioButtonList1" runat="server" DataTextField="answerName"
  DataValueField="answerID">
  </asp:RadioButtonList>
  </ItemTemplate>
  </asp:Repeater>
  </div>
  <asp:Button ID="submit" runat="server" Text="提交答卷" />
  </div>
  </form>
</body>
</html>


请问这个js验证错在哪?

------解决方案--------------------
<div>
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
改成 <div id="chk_all"> 
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">

js如下修改
j = 0;
var chk_all = document.getElementById("chk_all");
var check = chk_all.getElementsByTagName("radio");
for (i = 0; i < check.length; i++) {
if (check[i].checked == true) {
j++;
}
}