js监听
/**
* 全选
* @param val
* @constructor
*/
layui.use(['form'], function(){
var form = layui.form();
//全选
form.on('checkbox(allChoose)', function (data) {
$("input[name='check[]']").each(function () {
this.checked = data.elem.checked;
});
form.render('checkbox');
});
//单选
form.on('checkbox(oneChoose)', function (data) {
var i = 0;
var j = 0;
$("input[name='check[]']").each(function () {
if( this.checked === true )
{
i++;
}
j++;
});
if( i == j )
{
$(".checkboxAll").prop("checked",true);
form.render('checkbox');
}else
{
$(".checkboxAll").removeAttr("checked");
form.render('checkbox');
}
});
});Html
<tr> <th width="40" ><input type="checkbox" class="checkboxAll" lay-skin="primary" lay-filter="allChoose" ></th> <th width="210">商品名称</th> <th width="160">SKU</th> <th width="70">产品类型</th> <th width="140">价格(元)</th> <th width="140">发布时间</th> <th>操作</th> </tr> <tr> <td><input type="checkbox" name="check[]" value="2" lay-skin="primary" lay-filter="oneChoose"></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr>
本文由:xiaoshu168 作者:xiaoshu发表,转载请注明来源!