<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>