jquery validate 插件实例教程

2019-03-02 22:16|来源: 领悟书生

jquery validate是一个表单较难的jquery插件,在github上的地址是:https://github.com/jzaefferer/jquery-validation,应用比较简单,当然也可以从jquery的官网获取得到http://archive.plugins.jquery.com/project/validate。


使用的时候引用jquery的库和validate的库就可以了,使用方面看下面的例子。

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>jquery validate 插件实例01</title>
    <meta name="author" content="Administrator" />
    <link rel="stylesheet" type="text/css" href="js/css/screen.css" />
    <script type="text/javascript" src="js/jquery-1.9.0.js"></script>
    <script type="text/javascript" src="js/jquery.validate.js"></script>
    <script type="text/javascript">
    $(function(){
            $("#myform").validate({
            rules:{
        username:"required",
        address:{
                required:true,
            minlength:3
        },
        age:"digits",
        pwd:"required",
        cpwd:{
            equalTo:"#pwd"
        }
        },
        messages:{
        username:"用户名必须输入",
        address:{
                required:"用户地址必须输入",
            minlength:"地址不能小于3位"
        },
        age:"年龄必须是整数",
        pwd:"密码必须输入",
        cpwd:"两次密码不一致"
        }
    });
    });
    </script>
</head>
<body>
    <form id="myform" action="#">
    Username:<input type="text" id="username" name="username"/><br/>
    Address:<input type="text" id="address" name="address"/><br/>
    Age:<input type="text" id="age" name="age"/><br/>
    password:<input type="text" id="pwd" name="pwd"/><br/>
    confirm password:<input type="text" id="cpwd" name="cpwd"/><br/>
    <input type="submit" />
    </form>
</body>
</html>


本文链接:jquery validate 插件实例教程,由领悟书生原创

转载请注明出处【http://www.656463.com/article/358】

相关问答

更多
  • 实例教程.....[2023-04-11]

    我要自学网 http://www.51zxw.net/ AutoCAD应用教程集-eNet网络学院 http://www.enet.com.cn/eschool/zhuanti/jcwautocad/ AutoCAD室内外施工图绘制精讲教程-eNet硅谷动力网络学院 http://www.enet.com.cn/eschool/zhuanti/autocad2006/ cad快捷键大全 http://hi.baidu.com/langkeyan/blog/item/acbd16d1e29e4ed7572c8 ...
  • 当你设置对象属性的值时,你应该放在值之后而不是; 。 所以required: true;改变required: true; (三个地方), email: true; required: true, email: true, 然后你的代码就会起作用,就像这里: 小提琴 When you set values for object properties you should place , after values instead of ;. So change required: true; (three p ...
  • 这可以通过一个简单的两步过程完成: 声明你自己的验证方法 。 在该方法中,您将比较两个输入元素。 在两个输入元素之一中引用验证方法。 This can be done in a simple two-step process: Declare your own validation method. In that method you would compare the two input elements. Reference the validation method in one of the two ...
  • 你的代码: $.validator.addMethod("zero", function(input, element) { ... }); $("#studentid").validate({ // options }); 您应该将代码包装在DOM中,并按照下面的演示进行操作。 $(document).ready(function() { $.validator.addMethod("zero", function(input, element) { ... }); $("#s ...
  • 尝试使用正确的电子邮件验证消息