jquery Gets the check box (checkbox) for the selected value (array or single)

Source: Internet
Author: User

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:


  
 
   
  
  1. var id_array= New Array ();
  2. $ (' input[name= ' id "]:checked '). Each (function() {
  3. Id_array.push ($ (this). Val ()); //Add elements to an array  
  4. });
  5. 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


  
 
   
  
  1. if ($ ("#id"). attr ("checked")) {//checked
  2. Alert ($ ("#id"). Val ()); //Print the selected value  


jquery Gets the check box (checkbox) for the selected value (array or single)

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.