jquery – 如何在选中复选框时禁用和取消选中复选框?

我有一个 jquery脚本,它禁用一行中的所有复选框并将它们标记为已选中:

$(function() {
  enable_cb();
  $("#group1").click(enable_cb);
});

function enable_cb() {
  if (this.checked) {
     $("input.group1").attr("disabled",true);
     $("input.group1").attr("checked",true);
  } else {
     $("input.group1").removeAttr("disabled","checked");

  }
}

这是我的html:http://jsfiddle.net/3fksv/16/的小提琴

我希望其余的复选框再次显示为活动状态,并在取消选中该复选框时取消选中.我的剧本中我做错了什么?

解决方法

我认为你不能一次删除两个属性.您可能必须使用两次调用removeAttr()函数

$("input.group1").removeAttr("disabled");
$("input.group1").removeAttr("checked");

正如@nickf正确提到的,这些命令也可以链接

$("input.group1").removeAttr("disabled").removeAttr("checked");

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: <span id=&quot...
jQuery 添加水印 <script src="../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...