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:
- var checkValue=new Array();
- //or var checkValue=[];
- $('input[name="check "]:checked').each(function(){
- checkValue .push($( this ).val()); //Add an element to the array
- });
- var checkstr= checkValue .join( ',' ); // join array elements to build a string
- alert(checkstr);
The method of judging whether a single checkbox is selected and getting the selected value is as follows:
- if($("#id").is(":checked")){//选中
- alert($( "#id" ).val()); // print the selected value
- }