<form class="form-horizontal" action="/biz/patent/edit" method="post" enctype="multipart/form-data" data-toggle="validator" role="form" novalidate="true" id="patentEditForm"> <button class="btn btn-primary" type="button" id="but_sub">保存</button> <button class="btn btn-primary" type="button">保存返回列表</button> <button class="btn btn-warning" type="button" onclick="window.location=‘/biz/project/list‘;">返回</button></form>
$(document).ready(function(){ var buttonId; $(‘#patentEditForm‘).validator().on(‘submit‘, function (e) { if (e.isDefaultPrevented()) { // handle the invalid form... } else { // everything looks good! if(buttonId == "but_sub"){ var formData = new FormData($("#patentEditForm")[0]); $.ajax({ type:"POST", url:"/biz/", data: formData, dataType:"JSON", nsync:false, cache: false, contentType: false, processData: false, success:function(date){ switch(date.status){ case 1: $success("保存成功!"); break; case 1009: $error("保存失败!"); break; default : $error("没有提交信息"); } }, error:function(){ $error("没有提交信息"); } }); return false; } } }); $(".btn-primary").click(function(){ buttonId = $(this).attr("id"); $(‘#patentEditForm‘).trigger(‘submit‘); });
1.$(".btn-primary").click()和 $(‘#patentEditForm‘).validator().on(‘submit‘)两个事件的处理方法之间传递参数(用全局变量)。2.不用原来的表单提交,用.trigger(‘submit‘)方法在JavaScript里触发提交。
时间: 2024-10-11 00:31:48