Jquery obtains the checkbox selected values (one group and one)

Source: Internet
Author: User
Tags javascript array

Use jquery to obtain the selected Status values of a group or a single checkbox. The following example shows how to obtain the checkbox value of this set of name = id, assuming that there is a set of checkbox name values on the existing page as follows:

Var id_array = new Array (); $ ('input [name = "id"]: checked '). each (function () {id_array.push ($ (this ). val (); // Add an element to the array}); var idstr = id_array.join (','); // concatenates array elements to construct an alert (idstr) string );

The above mainly uses the jquery each method and the two array operation functions of javascript push and join. For details about the push and join functions, refer to this article:

JavaScript array operation function Summary (push, pop, join, shift, unshift, slice, splice, concat)

In addition, jquery determines whether a single checkbox is selected and the method to obtain the selected value is as follows:

If ($ ("# id "). attr ("checked") {// select alert ($ ("# id "). val (); // print the selected value}
Articles you may be interested in
  • Jquery checks whether checkbox is selected
  • Jquery $. ajax $. post or $. get: How to submit the checkbox Value
  • Common Values of Cache-control include private, no-cache, max-age, and must-revalidate.
  • Js: Click enter and move the cursor to the next input box.
  • Javascript determines whether the mouse is left or right-click-compatible with ie, firefox, chrome, and other major browsers
  • Use php functions in the smarty template and how to use multiple functions for a variable in the smarty Template
  • Js restrictions: Only English letters and numbers can be entered. Chinese characters and other special characters cannot be entered.
  • Js to determine whether an array contains repeated values

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.