开发者

is there a jquery one liner code for toggling ENABLED checkboxes?

Is there a jquery method/whatever to toggle all checkboxes EXCEPT disabled ones? i have this code right now:

$('.select-all-categories').toggle(function() {
  $('#test-categories input[type="checkbox"]').attr("checked", false);
  return false;
}, function() { 
  $('#test-categories input[type="checkbox"]').attr("checked", true);
  retur开发者_如何学Pythonn false;
});

and it works fine(selects/deselects all checkboxes). BUt some of the checkboxes are disabled and I would like it to NOT be affected by the toggle. Is there a way to do this WITHOUT doing a for each and looping through all and checking if they are disabled or not?


Use :enabled to only select checkboxes that are enabled:

$('#test-categories input[type="checkbox"]:enabled')

By the way, you can replace [type="checkbox"] with :checkbox:

$('#test-categories input:checkbox:enabled')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜