功能layui多表单验证提交

Posted 杨治中

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了功能layui多表单验证提交相关的知识,希望对你有一定的参考价值。

2021-06-22 15:10:51

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>form表单</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui/css/layui.css" />
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdn.bootcdn.net/ajax/libs/layui/2.6.8/layui.min.js"></script>
</head>

<body>
  <!-- 表单1 -->
  <form class="layui-form" action="" lay-filter="form_f1">
    <div class="layui-form-item">
      <!-- 必填 -->
      <div class="layui-inline">
        <label class="layui-form-label" for="f1_d">表单1</label>
        <div class="layui-input-block">
          <input type="text" name="f1_date" id="f1_d" class="layui-input" placeholder="请输入" autocomplete="off"
            lay-verify="required">
        </div>
      </div>
    </div>
    <!-- 提交 -->
    <div class="layui-form-item">
      <button type="submit" class="layui-btn layui-hide subItem" lay-submit="" lay-filter="formGroup">立即提交</button>
    </div>
  </form>
  <!-- 表单2 -->
  <form class="layui-form" action="" lay-filter="form_f2">
    <div class="layui-form-item">
      <!-- 必填 -->
      <div class="layui-inline">
        <label class="layui-form-label" for="f2_d">表单2</label>
        <div class="layui-input-block">
          <input type="text" name="f2_date" id="f2_d" class="layui-input" placeholder="请输入" autocomplete="off"
            lay-verify="required">
        </div>
      </div>
    </div>
    <!-- 提交 -->
    <div class="layui-form-item">
      <button type="submit" class="layui-btn layui-hide subItem" lay-submit="" lay-filter="formGroup">立即提交</button>
    </div>
  </form>
  <!-- 表单3 -->
  <form class="layui-form" action="" lay-filter="form_f3">
    <div class="layui-form-item">
      <!-- 必填 -->
      <div class="layui-inline">
        <label class="layui-form-label" for="f3_d">表单3</label>
        <div class="layui-input-block">
          <input type="text" name="f3_date" id="f3_d" class="layui-input sub" placeholder="请输入" autocomplete="off"
            lay-verify="required">
        </div>
      </div>
    </div>
    <!-- 提交 -->
    <div class="layui-form-item">
      <button type="submit" class="layui-btn layui-hide subItem" lay-submit="" lay-filter="formGroup">立即提交</button>
    </div>
  </form>

  <button type="button" class="layui-btn submitBtn">提交</button>
</body>


<script>
  $(function () 
    layui.use(['form', 'table', 'layer', 'laydate', 'element', 'util'], function () 
      var form = layui.form;
      var table = layui.table;
      var layer = layui.layer;
      var laydate = layui.laydate;
      //监听提交
      let sum = 0;
      form.on('submit(formGroup)', function () 
        sum++
        if(sum == 3)
          console.log("全部验证通过");
          let f1_data = form.val('form_f1')
          let f2_data = form.val('form_f2')
          let f3_data = form.val('form_f3')
          console.log('f1_data: ', f1_data);
          console.log('f2_data: ', f2_data);
          console.log('f3_data: ', f3_data);
        
        return false;
      );
      // 提交全部
      $('.submitBtn').on('click', function () 
        sum = 0
        $('.subItem').trigger('click');
      )
    );
  )

</script>

</html>```

以上是关于功能layui多表单验证提交的主要内容,如果未能解决你的问题,请参考以下文章

在LayUI表单中,有AJAX方式来提交表单吗

Layui表单验证失败的提醒方式,怎么改变一下

layui 自定义表单验证 以及提交表单

layui弹出表单提交后,界面model验证部分起作用

layui的表单验证,怎么通过手动触发

layui框架实现多图片手动上传和随表单提交方法