Jquery checks whether the check box is selected. jquery is selected.

Source: Internet
Author: User

Jquery checks whether the check box is selected. jquery is selected.

Jquery judges whether the check box is selected and how to select it.
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 () + ',' ;}}) Determine 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 ');}

The above is the method used by jquery to determine whether the check box is selected. I hope it will be helpful for you to learn and obtain it using js. For details, refer to JS to determine whether the check box is selected for an instance.

Related Article

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.