JQuery code for processing form elements

Source: Internet
Author: User

1. Get the value of the input class: $ ("input"). val ();

2. Get the textarea class value: $ ("textarea"). val ();

3. Obtain the value of the select class: $ ("select"). val ();

When the form contains multiple input classes (or textarea class and select class), the preceding method is used to obtain an array. Of course, you can add IDs to these controls to take a specific control value, for example, $ ("input # myID"). val ().

The following describes the value methods of each control:

1. input type = "text" single line text input box and input type = "password" password input box

$ ("Input"). val (); 2. input type = "radio" single vertex

$ ("Input: checked"). val (); // use checked to obtain the value of the selected single vertex. 3. input type = "checkbox" check box (worth noting)

$ ("Input: checked"). each (function (index ){
$ ("# Result"). append ($ (this). val () + "");
});
// Because the selection result of the check box is usually greater than 1, the result is an array.
// Use the. each () method to extract the selected values one by one.
// The result is appended to the section with the ID "result". 4. input type = "submit" (Form submission button)

The value method is the same as that of a single text input box, but it has no practical significance.

5. textArea multi-line text input box

$ ("Textarea"). val (); 6. select drop-down box (single choice and multiple choice)

$ ("Select"). val ();
// Note: if it is a check, the result is a string with a comma (,), for example, "select one, select two ". Note:

The value of a form Element usually occurs after the form is not submitted. In jQuery, we can use the following statement to determine the value:
$ ("Form"). submit (function (){
$ ("Input"). val ();
}); To set a value for a form element, you only need to set the value as a passing parameter, for example: $ ("input"). val ("jb51.net ");

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.