jquery选择器
选择祖先元素同级元素下的type=checked元素,并将checked设置为true
html
<div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" > 一人 </a> <label ><input type="checkbox" class="ace " id="allcheck"/> <span class="lbl"></span> 全选 </label> </h4> </div> <div id="collapseOne" class="panel-collapse collapse in"> <div class="panel-body"> <form role="form" action="#0" method="post" onsubmit="return beforeSubmit(this);"> <input type="hidden" name="_token" value="{{csrf_token()}}"> <input type="hidden" name="formurl" value="OneWord"/> <div class="row"> <div class="col-md-8"> <label class="pos-rel"> <input type="checkbox" class="ace auth_id" name="option[]" value="process"/> <span class="lbl"></span>公 </label> <label class="pos-rel"> <input type="checkbox" class="ace auth_id" name="option[]" value="oneListing"/> <span class="lbl"></span>一 </label> </div> <div class="form-group col-md-2"> <button type="submit" class="btn btn-primary btn-sm" >提交</button> </div> <div class="space"></div> </div> </form> </div> </div> </div>
js
//word 全选 $('#accordion .ace').on('click', function () { var $that = this; var $tmp = $($that).parents("div .panel-default"); var tmp1 = $("tmp>form").find("input"); if ($(this).is(':checked')) { $tmp.find('[type="checkbox"]').prop('checked', 'true'); } else { $tmp.find('[type="checkbox"]').prop('checked', ''); } });
//word 全选
$('#accordion .ace').on('click', function () {
var $that = this;
var $tmp = $($that).parents("div .panel-default");
var tmp1 = $("tmp>form").find("input");
if ($(this).is(':checked')) {
$tmp.find('[type="checkbox"]').prop('checked', 'true');
} else {
$tmp.find('[type="checkbox"]').prop('checked', '');
}
});