http://blog.csdn.net/fox123871/article/details/8108030

  1. <script type="text/javascript">
  2. //DropDownList验证方法
  3. $.validator.addMethod('selectNone',
  4. function(value, element) {
  5. return this.optional(element) ||(value!= -1);
  6. }, "请选择至少一项!");
  7. //ChekcBoxList验证方法
  8. /*
  9. $.validator.addMethod('atLeastOneChecked', function(value, element) {
  10. var checkedCount = 0;
  11. $("input[name^='" + <%=txtHistory.UniqueID %> + "']").each(function() {
  12. if ($(this).attr('checked')) { checkedCount++; }
  13. });
  14. return checkedCount>0;
  15. },"请选择至少一项");
  16. */
  17. // 手机号码验证
  18. $.validator.addMethod("isMobile", function(value, element) {
  19. var length = value.length;
  20. var mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
  21. return this.optional(element) || (length == 11 && mobile.test(value));
  22. }, "请正确填写您的手机号码");
  23. $(document).ready(function () {
  24. //验证CheckBoxList
  25. ValidateOptions = function(sender, args) {
  26. args.IsValid=false;
  27. var len = $("#history_DIV input:checked").length;
  28. args.IsValid = (len>0);
  29. };
  30. $("#form1").validate(
  31. {
  32. rules: {
  33. <%=txtVName.UniqueID %>: {
  34. required: true
  35. },
  36. <%=txtEmail.UniqueID %>: {
  37. required: true,
  38. email:true
  39. },
  40. <%=txtRemark.UniqueID %>: {
  41. required: true
  42. },
  43. <%=txtVSex.UniqueID %>: {
  44. required: function(element) {
  45. return $("input:radio[name='txtVSex']:checked").val()!="";
  46. }
  47. },
  48. <%=txtFrom.UniqueID %>:{
  49. selectNone: true
  50. },
  51. <%=txtMobile.UniqueID %>:{
  52. required:true,
  53. isMobile:true
  54. },
  55. <%=txtHistory.UniqueID %>:{
  56. //required: function(element) {
  57. //return ($("#history_DIV input:checked").length)>0;}
  58. //return $("#<%=txtHistory.UniqueID %> input[@type=checkbox]:checked").size()>0;
  59. // return $("input[name^='<%=txtHistory.UniqueID %>']").length>0
  60. //atLeastOneChecked: true
  61. }
  62. },
  63. messages: {
  64. <%=txtRemark.UniqueID %>:
  65. {
  66. required: "请填写报名理由"
  67. },
  68. <%=txtVSex.UniqueID %>:
  69. {
  70. required: "请选择性别"
  71. },
  72. <%=txtMobile.UniqueID %>:{
  73. required: "请填写手机号码"
  74. },
  75. <%=txtHistory.UniqueID %>:{
  76. required: "请选择届数"
  77. }
  78. }
  79. });
  80. });
  81. </script>
    1. <table width="750" border="0" cellpadding="0" cellspacing="5">
    2. <tr>
    3. <td width="150" height="40">
    4. 真实姓名:
    5. </td>
    6. <td width="600">
    7. <asp:TextBox ID="txtVName" runat="Server" Width="280px" />
    8. </td>
    9. </tr>
    10. <tr>
    11. <td height="40">
    12. 性别:
    13. </td>
    14. <td>
    15. <asp:RadioButtonList ID="txtVSex" runat="server" RepeatDirection="Horizontal">
    16. <asp:ListItem Text="男" Value="男"></asp:ListItem>
    17. <asp:ListItem Text="女" Value="女"></asp:ListItem>
    18. </asp:RadioButtonList>
    19. <br />
    20. </td>
    21. </tr>
    22. <tr>
    23. <td height="40">
    24. 手机号码:<br />
    25. </td>
    26. <td>
    27. <asp:TextBox ID="txtMobile" runat="Server" Width="280px" />
    28. <span>请填写真实手机号码方便接收活动通知</span>
    29. </td>
    30. </tr>
    31. <tr>
    32. <td height="40">
    33. E-Mail:<br />
    34. </td>
    35. <td>
    36. <asp:TextBox ID="txtEmail" runat="Server" Width="280px" CssClass="email" />
    37. <span>用于接收邮件通知</span>
    38. </td>
    39. </tr>
    40. <tr>
    41. <td height="40">
    42. 职业:<br />
    43. </td>
    44. <td>
    45. <asp:RadioButtonList ID="txtC_Name" runat="server" RepeatDirection="Horizontal">
    46. <asp:ListItem Text="学生" Value="1"></asp:ListItem>
    47. <asp:ListItem Text="职员" Value="2"></asp:ListItem>
    48. <asp:ListItem Text="经理" Value="3"></asp:ListItem>
    49. <asp:ListItem Text="家庭主妇" Value="4"></asp:ListItem>
    50. <asp:ListItem Text="自由职业者" Value="5"></asp:ListItem>
    51. </asp:RadioButtonList>
    52. </td>
    53. </tr>
    54. <tr>
    55. <td height="40">
    56. 报名人数:<br />
    57. </td>
    58. <td>
    59. <asp:RadioButtonList ID="txtC_EName" runat="server" RepeatDirection="Horizontal">
    60. <asp:ListItem Text="就我一人" Value="1"></asp:ListItem>
    61. <asp:ListItem Text="两人" Value="2"></asp:ListItem>
    62. <asp:ListItem Text="三人" Value="3"></asp:ListItem>
    63. </asp:RadioButtonList>
    64. </td>
    65. </tr>
    66. <tr>
    67. <td height="40">
    68. 报名理由:
    69. </td>
    70. <td>
    71. <asp:TextBox TextMode="MultiLine" Columns="50" Rows="5" ID="txtRemark" runat="Server" />
    72. <br />
    73. <span>优质理由怎么写?1.描述您为什么要申请2.描述活动那里吸引您 3.个性化自由发挥</span>
    74. </td>
    75. </tr>
    76. <tr>
    77. <td height="40">
    78. 参加过的:<br />
    79. </td>
    80. <td>
    81. <table>
    82. <tr>
    83. <td>
    84. <div id="history_DIV">
    85. <asp:CheckBoxList ID="txtHistory" runat="server" RepeatDirection="Horizontal">
    86. <asp:ListItem Text="无" Value="0">
    87. </asp:ListItem>
    88. <asp:ListItem Text="第一届" Value="1">
    89. </asp:ListItem>
    90. <asp:ListItem Text="第二届" Value="2">
    91. </asp:ListItem>
    92. <asp:ListItem Text="第三届" Value="3">
    93. </asp:ListItem>
    94. </asp:CheckBoxList>
    95. </div>
    96. </td>
    97. <td>
    98. <asp:CustomValidator ID="customCheckBoxListValidator" runat="server" ErrorMessage="至少选择一项"
    99. ClientValidationFunction="ValidateOptions" Display="Dynamic"  ForeColor="Red"/>
    100. </td>
    101. </tr>
    102. </table>
    103. </td>
    104. </tr>
    105. <tr>
    106. <td height="40">
    107. 了解活动:<br />
    108. </td>
    109. <td>
    110. 您从以下渠道得知本活动?
    111. <asp:DropDownList ID="txtFrom" runat="server">
    112. <asp:ListItem Text="请选择" Value="-1" Selected="True">
    113. </asp:ListItem>
    114. <asp:ListItem Text="搜索引擎" Value="1">
    115. </asp:ListItem>
    116. <asp:ListItem Text="朋友介绍" Value="2">
    117. </asp:ListItem>
    118. <asp:ListItem Text="平面媒介" Value="3">
    119. </asp:ListItem>
    120. <asp:ListItem Text="网站新闻" Value="4">
    121. </asp:ListItem>
    122. </asp:DropDownList>
    123. </td>
    124. </tr>
    125. <tr>
    126. <td height="60" colspan="2" align="center" valign="bottom">
    127. <asp:Button ID="btnInsert" Text="确认报名" runat="server" />
    128. </td>
    129. </tr>
    130. </table>

Jquery.Validate验证CheckBoxList,RadioButtonList,DropDownList是否选中的更多相关文章

  1. jQuery Validate验证框架详解

    转自:http://www.cnblogs.com/linjiqin/p/3431835.html jQuery校验官网地址:http://bassistance.de/jquery-plugins/ ...

  2. 【转】jQuery Validate验证框架详解

    jQuery校验官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation 一.导入js库 <script type=& ...

  3. jQuery Validate验证框架详解(jquery.validate.min.js)

    原博客 jQuery Validate验证框架详解 jQuery校验官网地址:https://jqueryvalidation.org/ 一.导入js库 <script type="t ...

  4. jQuery Validate验证框架详解(转)

    jQuery校验官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation 一.导入js库 <script type=& ...

  5. jquery.validate 验证机制

    jquery.validate 验证机制 金刚 juqery juqery.validate 在开发系统时,使用了jquery.validate.js 这个验证插件,来校验数据合法性 重点 验证是以i ...

  6. 弹出框页面中使用jquery.validate验证控件

    弹出框页面中使用jquery.validate验证控件有几个问题需要解决: 1,弹出框的提交事件完成后如何关闭弹出框页面? 2,提交不成功如何返回当前页? 3,如果知道验证事件成功? 之前笔者都是JS ...

  7. jQuery Validate验证框架与 jQuery ajaxSubmit的联合使用

    jQuery Validate验证框架自定义验证 第一步导入导入js库 <script src="<%=basePath%>static/js/jquery.js" ...

  8. 自整理的jquery.Validate验证表达式

    自整理几个jquery.Validate验证正则: 1. 只能输入数字和字母    /^[0-9a-zA-Z]*$/g jQuery.validator.addMethod("letters ...

  9. jQuery.Validate 验证,以及 remote验证, 多参数传递

    jQuery.Validate 验证: http://www.runoob.com/jquery/jquery-plugin-validate.html 教程网址,很简单, 今天主要在这里记录一下re ...

随机推荐

  1. 类似微博菜单 ,用swift语言编写

    自定义tabar搭载界面1.-自定义标题按钮_如图  2.10-导航条按钮封装 演示如下 源代码下载DSWeibo.zip

  2. dedecms导航

    {dede:global.cfg_cmsurl /} 首页链接 一级导航: {dede:channel type=“top”} [field:typelink]:导航链接 [field:typenam ...

  3. smarty中的变量使用

    在模板中输出动态数据可以用{},所以容易与css中的标签相互冲突,所以使用{literal}{/literal}标签包起来就不会用模板的解析方式解析,变量的来源有三种,用assign方法赋值,系统保留 ...

  4. Unity3D 之连按移动加速

    上代码: 效果是连续按W后,加速移动 为物体添加个拖拽效果,方便看运动轨迹. 将下面的脚本绑定到移动的物体上. 不过这里有一点很重要的需要去注意就是该方法不能放在 void FixedUpdate() ...

  5. Android屏幕保持唤醒状态

    我们程序偶尔会有需要屏幕一直或较长时间的保持唤醒状态,而用户的睡眠时间又设置的比较短.这时可能会对程序以及用户的使用造成一定的影响.在Android中有两种方法,可以让我们在我们需要保持唤醒的页面长时 ...

  6. Sqlserver基于流程控制

    流程控制语句只能在单个批处理段,用户自定义函数和存储过程中使用不能夸多个批处理或者用户自定义函数或者存储过程 批处理:一个或者多个语句组成的一个批处理,是因为所有语句一次性地被提交到一个sql实例,如 ...

  7. ASP FSO操作文件(复制文件、重命名文件、删除文件、替换字符串)

    ASP FSO操作文件(复制文件.重命名文件.删除文件.替换字符串)FSO的意思是FileSystemObject,即文件系统对象.FSO对象模型包含在Scripting 类型库 (Scrrun.Dl ...

  8. Oracle连接配置以及实例的备份和恢复

    背景:一个团队项目开发,不可能每个人都架设自己本地的数据库,大多数情况下是统一用服务器上的数据库,这时候就需要进行远程数据库的连接.而且有时候还需要进行数据库搬迁 ,这时候就需要进行数据库的备份和恢复 ...

  9. wamp优化

    友情链接:IT狂人博客 转载请注明作者:浮沉雄鹰 和本文链接:http://www.cnblogs.com/xby1993/p/3342085.html 一.修改php.ini, 修改上传文件大小限制 ...

  10. 【html】【10】div布局[div水平垂直居中]

    必看参考: http://www.jb51.net/css/28259.html 让div居中对齐缩写形式为: .style{margin:0 auto;} 数字0 表示上下边距是0.可以按照需要设置 ...