Item
Item
Item
Item
Item
Check
Uncheck
Reverse
$(function () {
//给jQuery结果集对象扩展全选方法
var actionHandler = {
check: function () {
//全部选择
this.prop("checked", true);
},
uncheck: function () {
//全部取消
this.prop("checked", false);
},
reverse: function () {
//逐个反选
this.each(function () {
this.checked = !this.checked;
});
}
};
jQuery.fn.extend(actionHandler);
//绑定事件
$("#bt-check").click(() => {
$(".item").check();
});
$("#bt-uncheck").click(() => {
$(".item").uncheck();
});
$("#bt-reverse").click(() => {
$(".item").reverse();
});
});
【Javascript】【jQuery】通过jQuery方法扩展,简化全选功能代码
关注
打赏