jquery get single or group value of checkbox checkbox

Assuming that an existing page has a group of checkboxes whose name value is check, the method to obtain the value of this group of checkboxes with name=check is as follows:

js code   Favorite code
  1. var checkValue=new Array(); 
  2. //or var  checkValue=[];
  3. $('input[name="check "]:checked').each(function(){  
  4.     checkValue .push($( this ).val()); //Add an element to the array  
  5. });  
  6. var  checkstr= checkValue .join( ',' ); // join array elements to build a string  
  7. alert(checkstr);  

 

 

The method of judging whether a single checkbox is selected and getting the selected value is as follows:

js code   Favorite code
  1. if($("#id").is(":checked")){//选中  
  2.     alert($( "#id" ).val()); // print the selected value  
  3. }  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324499532&siteId=291194637