jquery select all checkboxes

前端 未结 19 2726
情书的邮戳
情书的邮戳 2020-12-13 12:36

I have a series of checkboxes that are loaded 100 at a time via ajax.

I need this jquery to allow me to have a button when pushed check all on screen. If more are lo

19条回答
  •  时光取名叫无心
    2020-12-13 13:17

     Select / Deselect All
    
    Now here are  two versions of the toggleChecked function dependent on the semantics of your document. The only real difference is the jQuery selector for your list checkboxes:
    
    1: All checkboxes have a class of  “checkbox” ()
    function toggleChecked(status) {
    $(".checkbox").each( function() {
    $(this).attr("checked",status);
    })
    }
    
    2: All the checkboxes are contained within a div with an arbitary id:
    
    
    In this case the function would look like this: function toggleChecked(status) { $("#checkboxes input").each( function() { $(this).attr("checked",status); }) Have fun!

提交回复
热议问题