jQ 复选框 checkbox各种操作

1、是否选中

prop(name|properties|key,value|fn)
获取在匹配的元素集中的第一个元素的属性值

//选中复选框为true,没选中为false
$("input[type='checkbox']").prop("checked");

2、全选和全不选

//选中所有页面上的复选框
$("input[type='checkbox']").prop("checked", true);
//通过函数来设置所有页面上的复选框被选中。
$("input[type='checkbox']").prop("checked", function( i, val ) {
  return !val;
});

3、全禁用

$("input[type='checkbox']").prop({
  disabled: true
});
$("input[type='checkbox']").prop("disabled", false);

猜你喜欢

转载自blog.csdn.net/eddy23513/article/details/81030750