How to choose the all-in-choice plugin for jquery

Source: Internet
Author: User

jquery Select anti-select Plug-in, easy to enable you to achieve a single table table data selection and cancellation of all-in-one function, including examples, small and practical. Automatically determine the current number of selections, plus select All. Before we had jquery, we needed a large section of JS code to achieve this effect. With the powerful library of jquery, we can easily develop a jquery plugin that achieves this effect. I'll name it the JQuery.fn.check plugin. Front-end framework sharing

Before we build our plug-in, we want to consider its functional requirements:

The status of all check boxes varies with the state of the Select all check box, and if all check boxes are selected, the Select all check box is immediately selected, and if the number of check boxes currently selected is less than the total number of check boxes, the Select all check box is immediately unchecked; When all the checkboxes under the All-selected check box are clicked, it is time to determine the number of check boxes currently selected, so that the Select all check box is selected.

If you have the following check boxes:

. Code
  1. <p><input type= "checkbox"  name= " Checkall "  /> Select all </p>  
  2. <p><input type= "checkbox"  name= " Check "  /> radio 1 </p>  
  3. <p><input type= "checkbox"  name= " Check "  /> radio 2 </p>  
  4. <p><input type="checkbox" name="Check" /> Radio 3</p>

jquery All-in-the-election plug-ins and calls are as follows. Front-end framework sharing

. Code
  1. $ (function () {
  2. Call the Select All plugin
  3. $.fn.check ({checkall_name: "Checkall", Checkbox_name: "Check" })
  4. });
  5. Select All Plugins
  6. Checkall_name Action Select all check box name
  7. Checkbox_name the name name value of the checked box that is being manipulated does not have a uniform setting contains the value to start with XXX itself modification
  8. (function ($) {
  9. $.fn.check = function (options) {
  10. var defaults = {
  11.              checkall_name:  "Checkall_name" ,  //all marquee name   
  12. Checkbox_name: "Checkbox_name" //action check box name
  13. },
  14.         ops = $. Extend (defaults, options);   
  15.         e = $ ( Span class= "string" style= "Color:blue" > "input[name=" "  + ops.checkall_name + ),  //Select all   
  16.         f = $ ( Span class= "string" style= "Color:blue" > "input[name=" "  + ops.checkbox_name + ),  //radio   
  17. g = f.length; Number of check boxes to be manipulated
  18. F.click (function () {
  19.             $ ( "input[name =" "  + ops.checkbox_name + " ']:checked "). length == $ (" Input[name= ' "  + ops.checkbox_name + " [] " ). Length ? e.attr ( "checked" ,  !0 )  : e.attr ( " Checked ",  ! 1 );   
  20. &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;}),  e.click ( function  ()  {  
  21.              for  (I = 0 ; g >  i; i++)  f[i].checked = this.checked;  
  22. });
  23. };
  24. }) (JQuery);

How to choose the all-in-choice plugin for jquery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.