jquery Determines whether the check box is selected method _jquery

Source: Internet
Author: User

The jquery decision check box is checked and how to select the question to do a summary.
To get to the point, or when the page is like the next set of check boxes:

<input type= "checkbox" name= "fruit" value= "apple"/> Apples <input 
type= "checkbox" name= "fruit" value= "orange "/> Orange 
<input type=" checkbox "name=" fruit "value=" banana "/> Banana 
<input type=" checkbox "Name=" fruit "Value=" Grape "/> Grapes 

Then use Jquery to get the values of a set of checkboxes for Name=fruit as follows:

var checkval= '; 
$ ("Input[name= ' fruit ']:checkbox"). each (the function () { 
  if ($ (this). attr (' checked ')) { 
    checkval+=$ (.). Val ( )+','; 
  } 
}) 
Determine if the check box for the Name=fruit group has the selected option:
var flag=false; 
$ ("Input[name= ' fruit ']:checkbox"). each (function () { 
  if ($ (this). attr (' checked ')) { 
    flag=true; 
  } 
}) 
if (flag) { 
  alert (' has been selected '); 
} else{ 
  alert (' No options selected '); 
} 

The above is the jquery check box is selected method, I hope to learn some help, but also useful JS get, please refer to the "JS Judge check box is selected instance"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.