日期:2014-05-17 浏览次数:20509 次
function ControlNum() { var count = 0; var cArray = document.getElementsByTagName("input"); var i=0; var option_number = <%=option_num %>; var result_number =<%=result_num %>; var item_number = <%=item_num %>; var total = result_number*option_number; while(i<cArray.length){ count = 0 for(var j = 0;j<result_number;j++) { if (cArray[i].type == 'checkbox' && cArray[i].checked) { count++; } i++; } if(count == option_number) { continue; } else{ if(count > option_number) { alert("注意题目类型,请勿多选!"); return false; break; } else { alert("注意题目类型,请勿少选!"); return false; break; } } } }
<asp:Repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound"> <ItemTemplate> 题目: 第<%# Eval("question") %>题 <ul> <asp:Repeater ID="rptAnswer" runat="server"> <ItemTemplate> <li> <input id="<%# Eval("answergroup") %>" name="<%# Eval("answergroup") %>" type="checkbox" onclick="checkNum('<%# Eval("answergroup") %>')" /> <%# Eval("answer") %></li> </ItemTemplate> </asp:Repeater> </ul> </ItemTemplate> </asp:Repeater> <script language="javascript" type="text/javascript"> function checkNum(chkname) { var chkanswer = document.getElementsByName(chkname); var answernum = chkanswer.length; var falg = 0; for (var i = 0; i < answernum; i++) { if (chkanswer[i].checked) { falg++; if (falg > 2) { chkanswer[i].checked = false; } } } } </script>