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