gistfile1.txt $( document ).ready( function () { //当选择框为值$( "#signupForm" ).validate( {onkeyup:false,rules: {uname: {required: true,minlength: 4,remote:{url:"http://localhost/oschina/Addons_Project/Addons/index.php/Rbac/Manager/
$( document ).ready( function () { //当选择框为值 $( "#signupForm" ).validate( { onkeyup:false, rules: { uname: { required: true, minlength: 4, remote:{ url:"http://localhost/oschina/Addons_Project/Addons/index.php/Rbac/Manager/remoteName", type:"post", } }, password: { required: true, minlength: 5 }, confirm_password: { required: true, minlength: 5, equalTo: "#password" }, agree: "required" }, messages: { uname: { required: "用户名必须填写", minlength: $.validator.format("用户名长度必须大于{0}"), remote:$.validator.format("{0}已经被占用") }, password: { required: "密码框必须输入", minlength: $.validator.format("密码长度必须大于{0}") }, confirm_password: { required: "请输入确认密码", minlength: $.validator.format("密码长度必须大于{0}"), equalTo: "两次输入密码不一致" }, agree: "请阅读管理条例" }, errorElement: "em", errorPlacement: function ( error, element ) { // Add the `help-block` class to the error element error.addClass( "help-block" ); //需要判断单选框的情况 if ( element.prop( "type" ) === "checkbox" ) { error.insertAfter( element.parent( "label" ) ); } else { error.insertAfter( element ); } }, // 未通过验证的表单元素设置高亮 highlight: function ( element, errorClass, validClass ) { $( element ).parents( ".col-sm-5" ).addClass( "has-error" ).removeClass( "has-success" ); }, // 说明:与highlight操作相反 unhighlight: function (element, errorClass, validClass) { $( element ).parents( ".col-sm-5" ).addClass( "has-success" ).removeClass( "has-error" ); } } ); } ); //附远程验证方法 /*添加validate()用户名远程唯一验证方法*/ public function remoteName(){ if($_POST) { // $uname = $_POST['uname']; $uname=I('post.uname'); $data=$this->_model->remoteName($uname); if($data) { echo 'false'; }else{ echo 'true'; } exit(); } }