jquery.validate新的写法(jquery.validate1.13.js)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<script src="../js/jquery.js"></script>
<script src="../js/jquery.validate.js"></script>
<script>
  $().ready(function() {
    $("#registerForm").validate();
  });
</script>
  
<form id="registerForm" method="get" action="">
  <fieldset>
    <p>
      <label for="cusername">用户名</label>
      <input id="cusername" name="username" type="text" data-rule-required="true" data-rule-rangelength="[2,10]" data-msg-required="用户名不能为空" data-msg-rangelength="用户名长度必须是2到10个字符">
    </p>
    <p>
      <label for="cpassword">密码</label>
      <input id="cpassword" name="password" type="password" data-rule-required="true" data-rule-minlength="6" data-msg-required="密码不能为空" data-msg-minlength="至少设置6位密码">
    </p>
    <p>
      <label for="cconfirmpassword">确认密码</label>
      <input id="cconfirmpassword" name="confirmpassword" type="password" data-rule-equalTo="#cpassword" data-msg-equalTo="两次密码不一致">
    </p>
    <p>
      <label for="cemail">邮箱</label>
      <input id="cemail" name="email" data-rule-required="true" data-rule-email="true" data-msg-required="邮箱不能为空" data-msg-email="邮箱的格式不正确">
      </input>
    </p>
    <p>
      <label for="chasreferee">有推荐人请勾选</label>
      <input type="checkbox" id="chasreferee" name="hasreferee">
    </p>
    <p>
      <label for="creferee">推荐人</label>
      <input id="creferee" name="referee" data-rule-required="#chasreferee:checked" data-msg-required="推荐人不能为空">
      </input>
    </p>
    <p>
      <input type="submit" value="提交">
    </p>
  </fieldset>
</form>

看了之前的别人写的文章,貌似是依赖jquery.metadata.js这个库,然后写的时候以 class=”required email” 这样的形式来写,这样写起来好像有些乱,class本身是呈现样式的,现在被附上各种校验的规则,看上去似乎有些乱,不过好在新版本中,又有了新的写法,不依赖上面的js库,以 data-rule-验证规则、data-msg-提示信息 这样的格式来重新定义,更简单,更直观,更强大了。上面的测试通过

我的版本的jquery.validate1.13.js

然后这样的写法,控件中的messages不会生效,还会报错:Cannot read property 'call' of undefined 园子里面很多jquery.validate文章提到可以使用,我看是版本过时了,反正我没有试验出来。还有就是将验证卸载class里面我也是醉了。下面的测试错误!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="jquery.min.js"></script>
 
<!--<script type="text/javascript" src="jquery.validate.js"></script>-->
<script type="text/javascript" src="jquery.validate1.13.js"></script>
<script type="text/javascript" src="jquery.validate.message_cn.js"></script>
<script type="text/javascript" src="jquery.metadata.js"></script>
<script type="text/javascript">
$(function(){
    $.metadata.setType("attr", "validate");
    $("#signupForm").validate();
    //$("#signupForm").validate({ meta: "validate" });
    //$("#commentForm").validate();
})
 
</script>
</head>
 
<body>
<form id="signupForm" method="get" action="">
    <p>
  
 
<input id="email" name="email" validate="{required:true, email:true, messages:{required:'输入email地址', email:'你输入的不是有效的邮件地址'}}" />
    </p>
 
    <p>
        <input class="submit" type="submit" value="Submit"/>
    </p>
</form>
 
</body>
</html>

  

 

jquery.validate1.13的更多相关文章

  1. jquery.validate新的写法(jquery.validate1.13.js)

    <script src="../js/jquery.js"></script> <script src="../js/jquery.vali ...

  2. jQuery的13个优点

    1.轻量级 JQuery非常轻巧,采用Dean Edwards编写的Packer压缩后,大小不到30KB,如果使用Min版并且在服务器端启用Gzip压缩后,大小只有18KB. gzip: 每天一个li ...

  3. JS 循环遍历JSON数据 分类: JS技术 JS JQuery 2010-12-01 13:56 43646人阅读 评论(5) 收藏 举报 jsonc JSON数据如:{&quot;options&quot;:&quot;[{

    JS 循环遍历JSON数据 分类: JS技术 JS JQuery2010-12-01 13:56 43646人阅读 评论(5) 收藏 举报 jsonc JSON数据如:{"options&q ...

  4. jquery.validate1.9.0前台验证使用

    一.利用jquery.form插件提交表单方法使用jquery.validate插件 现象:当提交表单时,即使前台未验证通过,也照常提交表单. 解决办法: $('#myForm').submit(fu ...

  5. jQuery与ajax 基础运用

    jQuery是一个轻量级js框架,使用方便快捷,更是封装ajax处理方法,如$.load() $.get() $.post() 等 但最常用的方法还是$.ajax() 一.一般的格式为 $.ajax( ...

  6. jQuery插件之validation插件

    前面的话 最常使用javascript的场合就是表单的验证,而jQuery作为一个优秀的javascript库,也提供了一个优秀的表单验证插件——Validation.Validation是历史最悠久 ...

  7. jQuery使用简单示例 validate 插件

    摘录自:http://blog.csdn.net/u010320371/article/details/51104783用户登录 用户名 密码 确认密码 <!DOCTYPE html> & ...

  8. jquery.validate.js表单验证

    一.用前必备官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: http://jquery.bassist ...

  9. jQuery.Validate验证库详解

    一.用前必备官方网站:http://bassistance.de/jquery-plugins/jquery-plugin-validation/ API: http://jquery.bassist ...

随机推荐

  1. Android 随着输入框控件的清除功能ClearEditText,抄IOS输入框

    今天给大家带来一个非常有用的小控件ClearEditText,就是在Android系统的输入框右边增加一个小图标,点击小图标能够清除输入框里面的内容,IOS上面直接设置某个属性就能够实现这一功能.可是 ...

  2. 智能家居DIY

    近期智能家居比較火,将房子简单改造下,也算体验智能家居. 本文解说的是用无线的方式,长处是:不用改造现有线路,直接安装模块就可以实现想要的功能,花的钱也较少,共六百左右 =============== ...

  3. 制作service服务,shell脚本小例子(来自网络)

    事先准备工作:源码安装apache .安装目录为/usr/local/httpd 任务需求:1.可通过 service httpd start|stop|status|restart 命令对服务进行控 ...

  4. 构造NFS

    一.设备nfs-utils 伺服器: [root@server05 ftp]# yum install nfs-utils 这时会自己主动安装rpcbind需将此服务重新启动nfs服务才干启动 cli ...

  5. Java的结构之美【2】——销毁对象

    先来看一段代码: import java.util.Arrays; import java.util.EmptyStackException; /** * 2014年6月28日09:31:59 * @ ...

  6. earlysuspend调用过程

    1. 电源管理的状态 Android的Linux内核为系统提供了4种电源状态,内核的源码为当中的3种定义了名字和相应的宏定义,名字定义在kernel/power/suspend.c中: constch ...

  7. [LeetCode116]Path Sum

    题目: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up ...

  8. 求n阶勒让德多项式

    Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 161  Solved: 105 [Submit][Status][Web Board] Descrip ...

  9. Java彻底 - WEB容器的侦听具体解释 ServletContextListener

    WEB容器的侦听器ServletContextListener主要用于监测容器启动和 当破坏需要做一些操作,听众将能够使用此做. ServletContextListener在Spring开始,然后再 ...

  10. HDU 1176 免费馅饼(DP)

    职务地址:HDU 1176 以时间为横轴.11个点位纵轴构造一个矩阵.然后利用数字三角形的方法从上往下递推下去. 代码例如以下: #include <iostream> #include ...