• jquery.validate ajax方式验证


    在做网站的时候有一块需要用到jquery.validate插件 ajax方式的方式来验证原始密码是否正确,研究了研究加上博客园朋友的帮助,终于实现了。贴出代码

    <script type="text/javascript">
        $(function () {
            $("#form1").validate({
                rules: {
                    pwd: {
                        required: true,
                        remote: {
                            url: "@Url.Action("ValidatePwd", "UserInfo")",
                            type: "post",
                            dataType: "json",
                            data: {
                                pwd: function () {
                                    return $("#pwd").val();    //这个是取要验证的密码
                                }
                            },
                            dataFilter: function (data) {    //判断控制器返回的内容
                                if (data == "true") {
                                    return true;
                                }
                                else {
                                    return false;
                                }
                            }
                        }
                    },
                    password: {
                        required: true,
                        rangelength: [6, 16]
                    },
                    confirm_password: {
                        required: true,
                        rangelength: [6, 16],
                        equalTo: "#password"
                    }
                },
                messages: {
                    pwd: {
                        required: "请填写原始密码!",
                        remote: "原始密码不正确,请重新填写!"    //这个地方如果不写的话,是自带的提示内容,加上就是这个内容。
                    },
                    password: {
                        required: "请填写新密码",
                        minlength: jQuery.format("登录名长度在6-12位之间!")
                    },
                    confirm_password: {
                        required: "请填写确认密码!",
                        minlength: "密码需由6-16个字符(数字、字母、下划线)组成!",
                        equalTo: "两次输入密码不一致!"
                    }
                },
                onfocus: true,    
                onkeyup: false,    //这个地方要注意,修改去控制器验证的事件。
                onsubmit: false
            });

  • 相关阅读:
    js5
    js4
    js(3)
    JS内容(2)
    html复习
    js介绍及内容(1)
    定位2
    position定位
    CSS
    列表及行块转变
  • 原文地址:https://www.cnblogs.com/laihuayan/p/3916050.html
Copyright © 2020-2023  润新知