Jquery.Validate验证CheckBoxList,RadioButtonList,DropDownList是否选中
http://blog.csdn.net/fox123871/article/details/8108030
- <script type="text/javascript">
- //DropDownList验证方法
- $.validator.addMethod('selectNone',
- function(value, element) {
- return this.optional(element) ||(value!= -1);
- }, "请选择至少一项!");
- //ChekcBoxList验证方法
- /*
- $.validator.addMethod('atLeastOneChecked', function(value, element) {
- var checkedCount = 0;
- $("input[name^='" + <%=txtHistory.UniqueID %> + "']").each(function() {
- if ($(this).attr('checked')) { checkedCount++; }
- });
- return checkedCount>0;
- },"请选择至少一项");
- */
- // 手机号码验证
- $.validator.addMethod("isMobile", function(value, element) {
- var length = value.length;
- var mobile = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
- return this.optional(element) || (length == 11 && mobile.test(value));
- }, "请正确填写您的手机号码");
- $(document).ready(function () {
- //验证CheckBoxList
- ValidateOptions = function(sender, args) {
- args.IsValid=false;
- var len = $("#history_DIV input:checked").length;
- args.IsValid = (len>0);
- };
- $("#form1").validate(
- {
- rules: {
- <%=txtVName.UniqueID %>: {
- required: true
- },
- <%=txtEmail.UniqueID %>: {
- required: true,
- email:true
- },
- <%=txtRemark.UniqueID %>: {
- required: true
- },
- <%=txtVSex.UniqueID %>: {
- required: function(element) {
- return $("input:radio[name='txtVSex']:checked").val()!="";
- }
- },
- <%=txtFrom.UniqueID %>:{
- selectNone: true
- },
- <%=txtMobile.UniqueID %>:{
- required:true,
- isMobile:true
- },
- <%=txtHistory.UniqueID %>:{
- //required: function(element) {
- //return ($("#history_DIV input:checked").length)>0;}
- //return $("#<%=txtHistory.UniqueID %> input[@type=checkbox]:checked").size()>0;
- // return $("input[name^='<%=txtHistory.UniqueID %>']").length>0
- //atLeastOneChecked: true
- }
- },
- messages: {
- <%=txtRemark.UniqueID %>:
- {
- required: "请填写报名理由"
- },
- <%=txtVSex.UniqueID %>:
- {
- required: "请选择性别"
- },
- <%=txtMobile.UniqueID %>:{
- required: "请填写手机号码"
- },
- <%=txtHistory.UniqueID %>:{
- required: "请选择届数"
- }
- }
- });
- });
- </script>
- <table width="750" border="0" cellpadding="0" cellspacing="5">
- <tr>
- <td width="150" height="40">
- 真实姓名:
- </td>
- <td width="600">
- <asp:TextBox ID="txtVName" runat="Server" Width="280px" />
- </td>
- </tr>
- <tr>
- <td height="40">
- 性别:
- </td>
- <td>
- <asp:RadioButtonList ID="txtVSex" runat="server" RepeatDirection="Horizontal">
- <asp:ListItem Text="男" Value="男"></asp:ListItem>
- <asp:ListItem Text="女" Value="女"></asp:ListItem>
- </asp:RadioButtonList>
- <br />
- </td>
- </tr>
- <tr>
- <td height="40">
- 手机号码:<br />
- </td>
- <td>
- <asp:TextBox ID="txtMobile" runat="Server" Width="280px" />
- <span>请填写真实手机号码方便接收活动通知</span>
- </td>
- </tr>
- <tr>
- <td height="40">
- E-Mail:<br />
- </td>
- <td>
- <asp:TextBox ID="txtEmail" runat="Server" Width="280px" CssClass="email" />
- <span>用于接收邮件通知</span>
- </td>
- </tr>
- <tr>
- <td height="40">
- 职业:<br />
- </td>
- <td>
- <asp:RadioButtonList ID="txtC_Name" runat="server" RepeatDirection="Horizontal">
- <asp:ListItem Text="学生" Value="1"></asp:ListItem>
- <asp:ListItem Text="职员" Value="2"></asp:ListItem>
- <asp:ListItem Text="经理" Value="3"></asp:ListItem>
- <asp:ListItem Text="家庭主妇" Value="4"></asp:ListItem>
- <asp:ListItem Text="自由职业者" Value="5"></asp:ListItem>
- </asp:RadioButtonList>
- </td>
- </tr>
- <tr>
- <td height="40">
- 报名人数:<br />
- </td>
- <td>
- <asp:RadioButtonList ID="txtC_EName" runat="server" RepeatDirection="Horizontal">
- <asp:ListItem Text="就我一人" Value="1"></asp:ListItem>
- <asp:ListItem Text="两人" Value="2"></asp:ListItem>
- <asp:ListItem Text="三人" Value="3"></asp:ListItem>
- </asp:RadioButtonList>
- </td>
- </tr>
- <tr>
- <td height="40">
- 报名理由:
- </td>
- <td>
- <asp:TextBox TextMode="MultiLine" Columns="50" Rows="5" ID="txtRemark" runat="Server" />
- <br />
- <span>优质理由怎么写?1.描述您为什么要申请2.描述活动那里吸引您 3.个性化自由发挥</span>
- </td>
- </tr>
- <tr>
- <td height="40">
- 参加过的:<br />
- </td>
- <td>
- <table>
- <tr>
- <td>
- <div id="history_DIV">
- <asp:CheckBoxList ID="txtHistory" runat="server" RepeatDirection="Horizontal">
- <asp:ListItem Text="无" Value="0">
- </asp:ListItem>
- <asp:ListItem Text="第一届" Value="1">
- </asp:ListItem>
- <asp:ListItem Text="第二届" Value="2">
- </asp:ListItem>
- <asp:ListItem Text="第三届" Value="3">
- </asp:ListItem>
- </asp:CheckBoxList>
- </div>
- </td>
- <td>
- <asp:CustomValidator ID="customCheckBoxListValidator" runat="server" ErrorMessage="至少选择一项"
- ClientValidationFunction="ValidateOptions" Display="Dynamic" ForeColor="Red"/>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td height="40">
- 了解活动:<br />
- </td>
- <td>
- 您从以下渠道得知本活动?
- <asp:DropDownList ID="txtFrom" runat="server">
- <asp:ListItem Text="请选择" Value="-1" Selected="True">
- </asp:ListItem>
- <asp:ListItem Text="搜索引擎" Value="1">
- </asp:ListItem>
- <asp:ListItem Text="朋友介绍" Value="2">
- </asp:ListItem>
- <asp:ListItem Text="平面媒介" Value="3">
- </asp:ListItem>
- <asp:ListItem Text="网站新闻" Value="4">
- </asp:ListItem>
- </asp:DropDownList>
- </td>
- </tr>
- <tr>
- <td height="60" colspan="2" align="center" valign="bottom">
- <asp:Button ID="btnInsert" Text="确认报名" runat="server" />
- </td>
- </tr>
- </table>
Jquery.Validate验证CheckBoxList,RadioButtonList,DropDownList是否选中的更多相关文章
- jQuery Validate验证框架详解
转自:http://www.cnblogs.com/linjiqin/p/3431835.html jQuery校验官网地址:http://bassistance.de/jquery-plugins/ ...
- 【转】jQuery Validate验证框架详解
jQuery校验官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation 一.导入js库 <script type=& ...
- jQuery Validate验证框架详解(jquery.validate.min.js)
原博客 jQuery Validate验证框架详解 jQuery校验官网地址:https://jqueryvalidation.org/ 一.导入js库 <script type="t ...
- jQuery Validate验证框架详解(转)
jQuery校验官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation 一.导入js库 <script type=& ...
- jquery.validate 验证机制
jquery.validate 验证机制 金刚 juqery juqery.validate 在开发系统时,使用了jquery.validate.js 这个验证插件,来校验数据合法性 重点 验证是以i ...
- 弹出框页面中使用jquery.validate验证控件
弹出框页面中使用jquery.validate验证控件有几个问题需要解决: 1,弹出框的提交事件完成后如何关闭弹出框页面? 2,提交不成功如何返回当前页? 3,如果知道验证事件成功? 之前笔者都是JS ...
- jQuery Validate验证框架与 jQuery ajaxSubmit的联合使用
jQuery Validate验证框架自定义验证 第一步导入导入js库 <script src="<%=basePath%>static/js/jquery.js" ...
- 自整理的jquery.Validate验证表达式
自整理几个jquery.Validate验证正则: 1. 只能输入数字和字母 /^[0-9a-zA-Z]*$/g jQuery.validator.addMethod("letters ...
- jQuery.Validate 验证,以及 remote验证, 多参数传递
jQuery.Validate 验证: http://www.runoob.com/jquery/jquery-plugin-validate.html 教程网址,很简单, 今天主要在这里记录一下re ...
随机推荐
- 记工作中的git遇到的问题
看了 git 回退到某版本后,再在此版本上更新,无法push 操作前,我备份了修改了目录,准备建一个分支进行操作 我在本地revert了一次,commit到了远程仓库.然后上个版本的修改给恢复了... ...
- 你hack那么多啊,该怎么办
当我们通过javascript来操作css样式的时候,假如我们停留在css2的阶段,会发现操作起来并不是很困难.虽然存在一些浏览器兼容的问题,但我们通过封装自己的函数,不仅可以设置样式还能够获取样式. ...
- rs.open sql,conn,3,1中3,1代表什么
RecordSet中的open完全的语法是 SecordSet.Open Source,ActiveConnection,CursorType,LockType,Options 例如: rs.open ...
- Java语言编写计算器(简单的计算器)
Java编写的一个简单计算器,本人还比较菜,只能这样了,有点代码冗余,不能连续计算. import javax.swing.*; import java.awt.*; import java.awt. ...
- 20个linux命令行工具监视性能(上)
对于每一个系统管理员或网络管理员每天监视或调试linux系统的性能问题是一件非常困难的事,在it行业作为一个linux管理员五年之后,我开始知道监视和保持系统启动和运行有多么的困难.由于这个原因,我们 ...
- eclipse中启动Genymotion模拟器的错误
错误程序: Output file: C:\Users\wishwzp\.genymotion-eclipse.logLoading Genymotion libraryGenymotion dire ...
- 九度OJ 1513 二进制中1的个数
题目地址:http://ac.jobdu.com/problem.php?pid=1513 题目描述: 输入一个整数,输出该数二进制表示中1的个数.其中负数用补码表示. 输入: 输入可能包含多个测试样 ...
- ThinkPHP3.2 加载过程(一)
加载过程(官方介绍) : 用户URL请求 调用应用入口文件(通常是网站的index.php) 载入框架入口文件(ThinkPHP.php) 记录初始运行时间和内存开销 系统常量判断及定义 载入框架引导 ...
- linux系统使用密钥登录设置
使用密钥登录linux的操作步骤(使用putty): 1.用putty远程登录linux服务器,然后使用puttygen生成密钥,将生成的密钥保存,保存私钥将公钥复制保存到linux服务器的autho ...
- PHOTOSHOP 制作虚线和实线
1.制作实线可以直接用直线工具,选择合适的粗细大小. 2. 制作虚线首先要用钢笔或者绘图工具画出所需要的形状,如弧线,圆形等等 然后在路径面板中用画笔描边,画笔需要提前设置好粗细和间距,用方形 ...