<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CUSearch.WebForm1" %> <!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> <mce:script type="text/javascript" language="javascript"><!-- function checkOne() { var cbl_group = document.getElementById(cbl_group); var cbl_s = document.getElementsByTagName("input"); var checkCount = 0; for (var i = 0; i < cbl_s.length; i++) { if (cbl_s[i].id.indexOf("cbl_group_") != -1) { if (cbl_s[i].checked) { checkCount++; } } } if (checkCount == 0) { alert("请选择一个!"); return false; } else if (checkCount > 1) { alert("只能选择一个!"); return false; } else { alert("选择通过!"); return true; } } // --></mce:script> </head> <body> <form id="form1" runat="server"> <div> 请选择下面哪个今天起得最早(radiobutton):<br /> <asp:RadioButton GroupName="group" ID="rb_gril1" Text="黄丽" runat="server" /> <asp:RadioButton GroupName="group" ID="rb_gril2" Text="蒋君玲" runat="server" /> <asp:RadioButton GroupName="group" ID="rb_gril3" Text="陈盼盼" runat="server" /> <asp:RadioButton GroupName="group" ID="rb_gril4" Text="彭书敏" runat="server" /> </div> <br /> <br /> <br /> <br /> <div> 请选择下面哪个今天起得最早(CheckBoxList):<br /> <asp:CheckBoxList ID="cbl_group" runat="server"> <asp:ListItem Value="gril1" Text="黄丽" /> <asp:ListItem Value="gril2" Text="蒋君玲" /> <asp:ListItem Value="gril3" Text="陈盼盼" /> <asp:ListItem Value="gril4" Text="彭书敏" /> </asp:CheckBoxList> <br /> <asp:Button ID="btn_submit" runat="server" Text="提交" OnClientClick="return checkOne();" /> </div> </form> </body> </html>