<input type="text" id="subject_add" name="subject_add" lay-verify="subject_add" class="layui-input">
lay-verify="subject_add"
<script>layui.use(['form', 'layer'],
function() {
$ = layui.jquery;
var form = layui.form,
layer = layui.layer;
//自定义验证规则
form.verify({
subject_add: function(value) {
if (value.length < 5) {
return '科目名至少得2个字符';
}
},
});
//监听提交
form.on('submit(add)',
function(data) {
console.log(data);
//发异步,把数据提交给php
layer.alert("增加成功", {
icon: 6
},
function() {
// 获得frame索引
var index = parent.layer.getFrameIndex(window.name);
//关闭当前frame
parent.layer.close(index);
});
return false;
});
});</script>