核心的js代码:
jQuery('#q_CartMain .all_check').change(function () {
var set = jQuery(this).attr("data-set");
var checked = jQuery(this).is(":checked");
jQuery(set).each(function () {
if (checked) {
$(this).prop("checked", true);
} else {
$(this).prop("checked", false);
}
});
jQuery.uniform.update(set);
});
$('#Idcart_list .factory_selection').click(function () {
var setAttr = jQuery(this).attr("data-setAttr");
var ischoose = jQuery(this).is(":checked");
jQuery(setAttr).each(function () {
if (ischoose) {
$(this).prop("checked", true);
} else {
$(this).prop("checked", false);
}
});
jQuery.uniform.update(setAttr);
});
html代码:
结论:首先在全选的按钮上写一个自定义属性data-set="#ID .allchoose";#ID是全选遍历范围最大的box的id;.allchoose 是所有要选择的class名。