Brother article: http://blog.csdn.net/libin_1/article/details/50734967
方法一:if ($("#checkbox-id").get(0).checked) { //do something}方法二:if($(‘#checkbox-id‘).is(‘:checked‘)) { //do something}方法三:if ($(‘#checkbox-id‘).attr(‘checked‘)) { //do something}
<!doctype html><html lang="en"> <head> <meta charset="UTF-8" /> <script type="text/javascript" src="js/ Jquery-2.2.2.min.js "></script> <title>Document</title> <script type="Text/javascript">$( function() {$("#button"). Click ( function() { varH = $ ("input[type= ' checkbox ']"). length;vars ="'; for(vari =0; I < H; i++) {if($("input[type= ' checkbox ']"). EQ (i). is (': Checked ')) {s + = $ ("input[type= ' checkbox ']"). Get (i). value; }} alert (s); }) })</script> <script type="Text/javascript">$( function() {$("#button1"). Click ( function() { varH = $ ("input[type= ' Radio ')"). length;vars ="'; for(vari =0; I < H; i++) {if($("input[type= ' Radio ')"). EQ (i). is (': Checked ')) {s + = $ ("input[type= ' Radio ')"). EQ (i). Val (); }} alert (s); }) })</script> </head> <body> <input type="checkbox " Name="box" id="Box1" Value="Dive" checked="Checked" />Diving<input type="checkbox " name="box" id= "Box2" Value="Running" />Running<input type="checkbox " Name="box" id="Box3" Value="Listen to Music" />Listening to music<input type="button " name="button" id= "button" Value="Commit" /> <br /> <input type="Radio" name="box" id="Box1" Value="Dive" checked="Checked" />Diving<input type="Radio" name="box" id= "Box2" value="Running" />Running<input type="Radio" name="box" id="Box3" Value="Listen to Music" />Listening to music<input type="button " name="button" id= "Button1" Value="Commit" /> </body></html>
jquery Determines whether Checkbox,radio is selected