in the afternoon to write JS verification, there is a need to determine whether the checkbox is selected, access to relevant information, summed up the following 4 ways to share to everyone.
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>JQuery Determines if checkbox is selected 4 ways</title> <Scriptsrc= "Jquery-1.8.3.min.js"></Script> <Script> $(function(){ $('#agree'). On ('Click', function(){ if($("input[type= ' checkbox ']"). Is (': Checked')){ //check return True, not checked return falseConsole.log ('is selected'); }Else{Console.log ('not selected'); } }) $('#agree2'). On (' Change', function(){ //It could be onchange, or it could be the onclick. if($('#agree2'). attr ('checked') {Console.log ('is selected'); }Else{Console.log ('not selected'); } }) $('#agree3'). On (' Change', function(){ if($("#agree3"). Get (0). Checked) {Console.log ('is selected'); }Else{Console.log ('not selected'); } }) $('#agree4'). On (' Change', function(){ if($("#agree4"). Prop ('checked') {Console.log ('is selected'); }Else{Console.log ('not selected'); } }) }) </Script></Head><Body> <inputtype= "checkbox"name= "Agree"ID= "Agree">Agree to this Agreement<BR> <BR> <inputtype= "checkbox"name= "Agree"ID= "Agree2">Agree to this Agreement 2<BR> <BR> <inputtype= "checkbox"name= "Agree"ID= "Agree3">Agree to this Agreement 3<BR> <BR> <inputtype= "checkbox"name= "Agree"ID= "Agree4">Agree to this Agreement 4<BR> <BR></Body></HTML>
JQuery Determines if checkbox is selected 4 ways