新手小白,使用layui的时候,表单如何像普通表单那样提交呢?
如下:只需要在回调函数里 返回true,并且在form表单正常添加 action 和 method 属性就行!
如果返回false;将会拦截 阻止默认 form 跳转,此时可以在函数里通过 ajax 进行数据交互
<form class="layui-form" action="${basepath}/charpter07/logion" method="post"> <div class="demo-login-container"> <div class="layui-form-item"> <div class="layui-input-wrap"> <div class="layui-input-prefix"> <i class="layui-icon layui-icon-username"></i> </div> <input type="text" name="username" value="" lay-verify="required" placeholder="用户名" lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear"> </div> </div> <div class="layui-form-item"> <div class="layui-input-wrap"> <div class="layui-input-prefix"> <i class="layui-icon layui-icon-password"></i> </div> <input type="password" name="password" value="" lay-verify="required" placeholder="密 码" lay-reqtext="请填写密码" autocomplete="off" class="layui-input" lay-affix="eye"> </div> </div> <div class="layui-form-item"> <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-login">登录</button> </div> </div> </form> <script> layui.use(function () { var form = layui.form; var layer = layui.layer; // 提交事件 form.on('submit(demo-login)', function (data) { return true; // 返回false 阻止默认 form 跳转 }); }); </script>
标签:layer,form,layui,表单,提交,跳转 From: https://www.cnblogs.com/ruber/p/17581252.html