layui全选,单选(checkBox)
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
Box" class="checkBoxAll" lay-skin="primary" lay-filter="allChoose" >名称Box" name="check[]" value="2" lay-skin="primary" lay-filter="oneChoose"> 原文链接:https://www.f2er.com/jquery/422991.html 猜你在找的jQuery相关文章