layui文件上传前进行表单验证
<button type="submit" lay-submit="" lay-filter="BeforeUpload" class="layui-btn"> <i class="layui-icon"></i>上传 </button> <button type="button" class="layui-btn" style="display:none" id="Upload"> <i class="layui-icon"></i>上传 </button>
隐藏真正的上传按钮,用一个submit类型的按钮替代上传按钮,然后进行表单验证
form.on('submit(BeforeUpload)', function (data) { //表单验证 $("#Upload").click(); return false; });