多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] # 9.表单提交 - `form` 中加入 `action` 和 `method`, - 提交按钮中加入 `lay-submit="" lay-filter="submit" ` 即可 ``` <form class="layui-form" action="{:url('rbac/roleAddPost')}" method="post"> //todo <button type="button" lay-submit="" lay-filter="submit" class="layui-btn">增加</button> </form> ``` >这个方法有一个缺点,提交之后就关闭当前弹出窗口 >注:这里是在 `jqajax.js` 中书写的! 如图所示: ![mark](http://qiniu.newthink.cc/blog/20171020-153527207.png) # 自定义跳转到其他页面! 原理:重新监听 `submit2`,以前是 `submit` ``` <a class="layui-btn" lay-submit="" lay-filter="submit2">立即提交</a> <script src="__STATIC__/larry/js/admin.js"></script> <script> layui.use(['jqajax','form','layer'],function(){ var form = layui.form; var runAjax = new layui.jqajax(); form.on('submit(submit2)',function (data) { var params = { method: 'post', url: data.form.getAttribute('action'), data: data.field }; runAjax.ajax(params); runAjax.complete = function (ret) { layer.closeAll(); if(ret){ if (ret.msg) { layer.msg(ret.msg,{ time:3000 },function(){ window.location.href = ret.url; }) } } } }); }); </script> ``` 或者: ``` $('form').submit(); ```