validation+layer+ajax 提交验证表单 $("#form-user-add").validate({rules:{admin_name:{required:true,maxlength:16,},admin_cname:{required:true,maxlength:8,},email:{required: true, email: true}}, messages: { admin_name: { required: "请输入
$("#form-user-add").validate({ rules:{ admin_name:{ required:true, maxlength:16, }, admin_cname:{ required:true, maxlength:8, }, email:{ required: true, email: true } }, messages: { admin_name: { required: "请输入用户账号", maxlength: "账号长度不能大于 16 个字符!" }, admin_cname: { required: "请输入用户姓名", maxlength: "用户名不能大于8个字符!" }, email: "请输入一个正确的邮箱" }, onkeyup:false, focusCleanup:true, /* 失去焦点时不验证 */ onfocusout: false, success:"valid", //重写showErrors showErrors: function (errorMap, errorList) { var msg = ""; $.each(errorList, function (i, v) { //msg += (v.message + "\r\n"); //在此处用了layer的方法,显示效果更美观 layer.tips(v.message, v.element, { time: 2000 }); return false; }); }, submitHandler:function(form){ $(form).ajaxSubmit({ type: 'post', url: "{:url('Aduser/aduserAdd')}" , success: function(json){ layer.msg(json.msg,{icon:json.status,time:1000}); //只有成功时,关闭弹框刷新父级iframe页面 if (json.status===1) { setTimeout(function() { window.parent.location.reload(); }, 1000); } }, error: function(XmlHttpRequest, textStatus, errorThrown){ layer.msg('error!',{icon:2,time:1000}); } }); //自动关闭弹窗 // var index = parent.layer.getFrameIndex(window.name); // parent.$('.btn-refresh').click(); // parent.layer.close(index); } });