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?
- <div style="margin-top:150px;" >
- <input Type= ' checkbox ' name= ' test[' class= ' checkbox ' value= ' CheckBox1 ' >checkbox1
- <input type= ' checkbox ' name= ' test[' class= ' checkbox ' value= ' checkbox2 ' >checkbox2
- <input type=' checkbox ' name=' test[] ' class=' checkbox ' value=' Checkbox3 ' >checkbox3
- </div>
- <div style="margin-top:50px;" >
- <input type= "Radio" name= "test1" value = " Radio1 " class= ' radio ' > radio1
- <input Type= "Radio" name= " Test1 " value = " Radio2 " class= ' radio ' >RADIO2&NBSP;&NBSP;
- <input type="Radio" name="test1" value = "Radio3" class=' Radio ' > Radio3
- </div>
Two, Checkbok,radio selected
Method 1,
View copy print?
- These two methods belong to a class
- $ ('. checkbox:checked ');
- $ (' input[type^=checkbox]:checked ');
Method 2,
View copy print?
- $ ('. CheckBox '). Filter (': checked ');
Method 3
View copy print?
- $ ('. CheckBox '). each (function () {
- if ($ (this). Is (": Checked")) {
- Alert (This). Val () +": is checked");
- }else{
- Alert (This). Val () +": Are not checked");
- }
- })
Replace the above. CheckBox with. Radio, you can judge the selection of the radio tag.
jquery checkbox Radio Tab 3 ways to select