自定义的验证方法Remote
jQuery.metadata.setType("attr", "validate"); var opts = null; var isValidationGroup = false; jQuery(document).ready(function () { InitRules(); if (isValidationGroup) { if (opts != undefined || opts != null) { jQuery("#form1").validate(jQuery.extend(opts, { onsubmit: false })); } else { jQuery("#form1").validate({ onsubmit: false }); } InitValidationGroup(); } else { if (opts != undefined || opts != null) { jQuery("#form1").validate(opts); } else { jQuery("#form1").validate(); } } }); function GetRemoteInfo1(postUrl, data) { var remote = { type: "POST", async: false, url: postUrl, dataType: "text", data: data, dataFilter: function(dataXML) { var result = new Object(); if (dataXML == "1") { result.Result = false; result.Msg="已存在,另换一个试试。"; return result; } else { result.Result =true; return result; } } }; return remote; } function InitRules() { var dataCode = { username: function () { return $("#txtUserName").val(); }, key:function(){ return "CheckSysAdminName"; } }; var remoteCode = GetRemoteInfo1('/Service/sysHandle.ashx', dataCode); opts = { rules: { txtUserName: { required: true, remote:remoteCode }, txtPass:{ required: true, minlength: 6 }, txtAgainPass:{ required: true, equalTo: "#txtPass" }, txtName:{ required: true } }, messages: { txtUserName: { required: "请输入账号。" }, txtPass:{ required: "请输入密码。", minlength: "至少输入6位的密码。" }, txtAgainPass:{ required: "请输入确认密码。", equalTo: "密码不一致。" }, txtName:{ required:"请输入姓名。" } } , success: function (label) { label.html(" ").attr("class", "success").siblings("label").remove(); }, errorPlacement: function (error, element) { $(element).next("span").find(".success").remove(); error.appendTo(element.next("span")); } } }