jquery checkbox Radio Tab 3 ways to select

Source: Internet
Author: User

Zhang Ying published in 2013-07-16

Category: Js/jquery

Tags: checkbox, jquery, Radio, checked

jquery is flexible, there are many ways to check the checkbox radio tag, and here are just a few examples of three common methods.

One, test the HTML

View copy print?
  1. <div style="margin-top:150px;" >
  2.     <input  Type= ' checkbox '  name= ' test['  class= ' checkbox '   value= ' CheckBox1 ' >checkbox1   
  3.     <input  type= ' checkbox '  name= ' test['  class= ' checkbox '  value= ' checkbox2 ' >checkbox2   
  4. <input type=' checkbox ' name=' test[] ' class=' checkbox ' value=' Checkbox3 ' >checkbox3
  5. </div>
  6. <div style="margin-top:50px;" >
  7.     <input  type= "Radio"  name= "test1"  value =  " Radio1 " class= ' radio '  > radio1  
  8.     <input  Type= "Radio"  name= " Test1 " value = " Radio2 " class= ' radio '  >RADIO2&NBSP;&NBSP;
  9. <input type="Radio" name="test1" value = "Radio3" class=' Radio ' > Radio3
  10. </div>

Two, Checkbok,radio selected

Method 1,

View copy print?
    1. These two methods belong to a class
    2. $ ('. checkbox:checked ');
    3. $ (' input[type^=checkbox]:checked ');

Method 2,

View copy print?
    1. $ ('. CheckBox '). Filter (': checked ');

Method 3

View copy print?
    1. $ ('. CheckBox '). each (function () {
    2. if ($ (this). Is (": Checked")) {
    3. Alert (This). Val () +": is checked");
    4. }else{
    5. Alert (This). Val () +": Are not checked");
    6. }
    7. })

Replace the above. CheckBox with. Radio, you can judge the selection of the radio tag.

jquery checkbox Radio Tab 3 ways to select

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.