Home > Web Front-end > JS Tutorial > jQuery code for processing form elements_jquery

jQuery code for processing form elements_jquery

WBOY
Release: 2016-05-16 18:34:32
Original
1192 people have browsed it

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

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

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

When the form contains multiple input classes (or textarea class and select class), using the above method will get one array. Of course, you can add IDs to these controls to get the value of a specific control, for example: $("input#myID").val().

The following will introduce the value methods of each control one by one:

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

$("input").val();2. input type="radio" radio button

$("input:checked").val(); //Use checked, take the value of the selected radio button 3. input type="checkbox" check box (noteworthy)

$("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 array.
//Use the .each() method to take out the selected values ​​one by one.
//The result here will be appended to the paragraph with the ID "result" 4. input type="submit" (form submission button)

Value method and single-line text input box The method is the same, but it has no practical significance.

5. textArea multi-line text input box

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

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

takes the value of form elements, usually after the form is submitted. In jQuery we can use the following statement to judge:
$("form").submit(function(){
$("input").val();
}); To set the value of the form element, just use the value to be set as the passing parameter, for example: $("input").val(" jb51.net");

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template