Jquery checks whether the check box is selected

Source: Internet
Author: User

Recently, I summarized the question about how to determine whether to select the check box in javascript. Because Jquery is used more recently, I also want to summarize the question about how to determine whether to select and how to select the check box in jquery.

Enter the subject, or when there is a set of check boxes on the page:

<Input type = "checkbox" name = "fruit" value = "apple"/> apple <input type = "checkbox" name = "fruit" value = "orange"/> orange <input type = "checkbox" name = "fruit" value = "banana"/> banana <input type = "checkbox" name = "fruit" value = "grape"/> grape

You can use Jquery to obtain the value of a set of check boxes with name = fruit as follows:

var checkVal='';$("input[name='fruit']:checkbox").each(function(){ if($(this).attr('checked')){checkVal+=$(this).val()+',';}})

Check whether the check box of 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 ('selected ');} else {alert ('no option selected ');}
Articles you may be interested in
  • Javascript checks whether the check box is selected
  • Jquery checks whether checkbox is selected
  • Js determines whether the variable is a number
  • Js to determine whether an array contains repeated values
  • Js determines whether a value exists in a js Array
  • How does js determine whether the scroll wheel is scroll down or up?
  • Js checks whether the image is loaded and obtains the image width.
  • Php determines whether the string is full of English, pure Chinese, and a combination of Chinese and English

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.