jQuery implements a simple operation of Checkbox

For the selection of the check box group, all options, not all, acquire the value of the value of the selected check box

1. Click the full-selection button, check the box group all selected or all Cancel.
2. Implement the linkage of the full-elect button and the check box group. When there is no selected box group, then the Id = ‘checkall”s full-selection button should be unchecked; when check box group After all selected, the alllect button should also be selected.
3. Get the value of the selected check box.

   Operating operations for the check box group    $ (Function () {/ * completely select Checkbox button's checked, so you can use this.checked. Note: $ (this) .Checked Is wrong * / $ ('# Checkedall'). Click (Function () {$ ('[Name = Item]: checkbox'). Prop ('Checked', this.checked);}; / * Judgment complex The total number of boxes, whether or not the number of selected check boxes is equal: all the elections are not equal: there is no full selection * / $ ('[name = item]: checkbox'). Click (function () {/ * get UL Name = Item check box * / var $ checkedArray = $ ('[name = item]: checkbox'); / *? # $ckedArray.Filter( ': CheckEd ') -----> Already selected check box * / $ (' # CheckedAll '). Prop (' Checked ', $ CheckedArray.Length == $ CheckedArray.Filter (': checked '). Length) });});   $ (Function () {// Get the value of the selected check box VAR checkArray = new array (); // put the selected Checkbox's value var count; // The number of numbers have been selected ('# btn_submit'). Click (function () {checkedArray.length = 0; count = 0; $ ('[name = item]: checkbox: checked'). Each (Function). Each {CheckedArray.push ($ (this) .val ()); count ++;}); if (CheckedArray.Length == 0) {Alert ("Please check one at least."); return; Select the value of the check box: "+ CHECKEDARRAY +" \ n "+" selection check box bit: "+ count);});}          Basketball   
    Badminton
  • Running
  • For shortcomings in the code, it is not simple enough to be simple. Optimized place, if there is any better ideas and implementation methods, welcome to exchange learning.
  • The above is all the content of this article, I hope to help everyone, I hope everyone will support Tumi Cloud.
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment