jquery validate的用法举例

发布时间:2019-10-25编辑:脚本学堂
分享一个jquery中validate验证的例子,学习下jquery validate的用法,有需要的朋友参考下,希望对大家有所帮助。

本例子的效果图:
 

<a href=http://www.jb200.com/jb/jquery/ target=_blank class=infotextkey>jquery</a> validate的用法

完整代码:
 

复制代码 代码示例:
<title>jquery validate的用法_脚本学堂_http://www.jb200.com</title>
    <script src="Jquery1.7.js" type="text/javascript"></script>
    <script src="jquery.validate.js" type="text/javascript"></script>
    <script src="messages_cn.js" type="text/javascript"></script>
    <style type="text/css">
    .bitian
    {
        color:Red;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            $('#form1').validate({
                rules: {
                    username: { required: true, minlength: 6, maxlength: 12 },
                    password: { required: true, minlength: 6, maxlength: 12 },
                    passwordok: { required: true, equalTo: "#pwd" },
                    homepage:{required:true,url:true },
                    birthday:{required:true,dateISO:true},
                    blood:{required:true,digits:true},
                    email:{required:true,email:true}
                },
                errorplacement:function(error,element){
                error.appendTo(element.siblings('span'));
                }
            })
        })
    </script>
</head>
<body>
    <form id="form1">
    <table>
        <tr>
            <td>
                用户名:
            </td>
            <td>
                <input name="username" type="text" /><span class="bitian">*</span>
            </td>
        </tr>
        <tr>
            <td>
                密码:
            </td>
            <td>
                <input id="pwd" name="password" type="text" /><span class="bitian">*</span>
            </td>
        </tr>
        <tr>
            <td>
                确认密码:
            </td>
            <td>
                <input name="passwordok" type="text" /><span class="bitian">*</span>
            </td>
        </tr>
        <tr>
            <td>
                主页:
            </td>
            <td>
                <input name="homepage" type="text" /><span class="bitian">*</span>
            </td>
        </tr>
        <tr>
            <td>
                生日:
            </td>
            <td>
                <input name="birthday" type="text" /><span class="bitian">*</span>
            </td>
        </tr>
        <tr>
            <td>
                血压:
            </td>
            <td>
                <input name="blood" type="text" /><span class="bitian">*</span>
            </td>
        </tr>
        <tr>
            <td>
                邮箱:
            </td>
            <td>
                <input name="email" type="text" /><span class="bitian">*</span>
            </td>
        </tr>
        <tr>
            <td>
                <input id="Submit1" type="submit" value="提交" />
            </td>
        </tr>
    </table>
    </form>
</body>