layui的form表单的checkbox全选与全不选问题
<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8″>
<meta name=”viewport”
content=”width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0″>
<title>layui在线调试</title>
<link rel=”stylesheet” type=”text/css” href=”./utils/layui-v2.5.4/layui/css/layui.css”>
<style>
body {
margin: 10px;
}
.demo-carousel {
height: 200px;
line-height: 200px;
text-align: center;
}
</style>
</head>
<body>
<form class=”layui-form”>
<div class=”checkallbox”>
<input lay-skin=”primary” type=”checkbox” id=”checkall” name=”type” lay-filter=”allChoose”
value=”checkall” /><span>全选</span></div>
<div class=”seach-box”>
<ul>
<li><input lay-skin=”primary” type=”checkbox” name=”like1[aaa]” value=”111″ /><span>aaa</span></li>
<li><input lay-skin=”primary” type=”checkbox” name=”like1[bbb]” value=”222″ /><span>bbb</span></li>
<li><input lay-skin=”primary” type=”checkbox” name=”like1[ccc]” value=”333″ /><span>ccc</span></li>
<li><input lay-skin=”primary” type=”checkbox” name=”like1[ddd]” value=”444″ /><span>ddd</span></li>
</ul>
</div>
</form>
<script src=”./utils/layui-v2.5.4/layui/layui.js”></script>
<script src=”./utils/jquery-3.4.1.min.js”></script>
<script>
layui.use([‘form’, ‘laypage’, ‘layer’, ‘table’, ‘carousel’, ‘upload’, ‘element’, ‘slider’], function () {
var form = layui.form//日期
, laypage = layui.laypage //分页
, layer = layui.layer //弹层
, table = layui.table //表格
, carousel = layui.carousel //轮播
, upload = layui.upload //上传
, element = layui.element //元素操作
, slider = layui.slider //滑块
form.on(‘checkbox(allChoose)’, function (data) {
var child = $(“.seach-box input[type=’checkbox’]”);
child.each(function (index, item) {
item.checked = data.elem.checked;
});
form.render(‘checkbox’);
});
});
</script>
</body>
</html>
版权声明:本文为gdluck原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。