jquery.validate验证,jquery.Form插件提交,主要可以异步提交文件




<script type="text/javascript"> $(function () { $form = $("#manuForm"); $btnSub = $("#btnSubmit"); ///ajaxForm提交表单 $form.ajaxForm({ type: "post", datatype: "json", beforeSerialize: function () { $btnSub.val("提交中...").attr('disabled', 'true'); }, success: function (json) { var data = eval("(" + json + ")"); if (data.msg == "ok") { alert('提交成功!'); } else { alert('操作失败,可能的原因是:\n' + data.msg); } }, error: function (er) { alert('未能连接至服务器!\n'); }, complete: function () { //$btnSub.val("提交").attr('disabled', 'false'); location.replace(location.href); } }); ////Validate验证表单 $form.validate({ errorPlacement: function (error, element) { $tdError = $("<td>").append(error); element.parent("td").after($tdError); }, //设定规则 rules: { ManuTitle: { required: true, rangelength: [1, 25] }, ManuFund: { rangelength: [1, 25] }, ManuContent: { maxlength: 1000 }, File: { required: true } }, //这里是与规则对应的错误代码 messages: { ManuTitle: { required: "请输入标题", rangelength: "不能超过25个字" }, ManuFund: { rangelength: "不能超过25个字" }, ManuContent: { maxlength: "不能超过1000字" }, File: { required: "必须添加稿件文件附件" } } }); }); </script>

 

posted @ 2014-03-20 17:22  三台  阅读(361)  评论(0编辑  收藏  举报