jQuery Validate remote多参数

版权声明:LT https://blog.csdn.net/LitongZero/article/details/87874287

jQuery Validate remote多参数 校验

使用场景

jQuery Validate remote验证时,需要传入多个字段。

解决方法

实例

$("#myForm form").validate({
        onkeyup: false,
        focusCleanup: false,
        rules: {
            username: {
                required: true,
                stringCheck: true,
                maxlength: 30,
                remote: {
                    url: "user/checkUsername",
                    type: "post",
                    data: {
                        id: function(){
                            return $('input[name="id"]').val();
                        },
                        username: function () {
                            return $('#username').val();
                        },
                        userCode: function () {
                            return $('#userCode option:selected').val();
                        }
                    }
                }
            }
        },
        messages: {
            username: {
                required: "请输入用户名",
                maxlength: "用户名不能超过30个字符",
                remote: "用户已存在"
            }        
        },
        submitHandler: function (form) {
            //
        },
        errorPlacement: function (error, element) {
            //
        }
    });

备注

上面实例在验证时,传入了3个参数。

传入参数时,必须使用如下格式

id: function(){
    return $('input[name="id"]').val();
 },

猜你喜欢

转载自blog.csdn.net/LitongZero/article/details/87874287