each method of popularizing jquery and the two arrays of JavaScript operation function Push and join
each () method specifies the function to run for each matching element.
Grammar
$ (selector). each (function (index,element))
Index-the index position of the selector
Element-current elements (can also use the "this" selector)
The push () method adds one or more elements to the end of the array and returns the new length.
Grammar
Arrayobject.push (Newelement1,newelement2,...., newelementx)
Parameters |
Description |
Newelement1 |
Necessary. The first element to add to the array. |
Newelement2 |
Optional. The second element to add to the array. |
Newelementx |
Optional. You can add multiple elements. |
the Join () method is used to put all the elements in an array into a string. The elements are delimited by the specified delimiter.
Arrayobject.join (separator)
Separator is optional. Specifies the delimiter to use. If this argument is omitted, a comma is used as the delimiter.
Example:
var arr = ["A", "B", "C", "D", "E"]; document.write (Arr.join ("-")); Results: A-b-c-d-e.
Use jquery to get the value of a set of checkboxes, as follows:
- var id_array= New Array ();
- $ (' input[name= ' id "]:checked '). Each (function() {
- Id_array.push ($ (this). Val ()); //Add elements to an array
- });
- var idstr=id_array.join (', '); //Connect array elements to construct a string
jquery Determines whether a single checkbox is selected and gets the selected value as follows
- if ($ ("#id"). attr ("checked")) {//checked
- Alert ($ ("#id"). Val ()); //Print the selected value
jquery Gets the check box (checkbox) for the selected value (array or single)