Get the value of the form control by using jQuery to operate the DOM, and use the jquerydom form control.
This document describes how to use jQuery to operate DOM to obtain the value of a form control. Share it with you for your reference. The specific analysis is as follows:
The biggest difference between HTML attributes and DOM attributes is probably the value of the Form Control. For example, the value attribute of the text box in the DOM is called defaultValue, and there is no value attribute in the DOM. For the select element, the value of the option is usually obtained through the selectedIndex attribute in the DOM or by the selected Attribute of the Option element.
Because of these differences, it is best not to use the. attr () method when obtaining and setting the value of the Form Control. For the option list, it is best not to use the. prop () method. Then, we recommend that you use the. val () method provided by jQuery:
Copy codeThe Code is as follows: // get the current value of the text input box
Var inputValue = $ ('# my-input'). val ();
// Obtain the current value of the Option List
Var selectValue = $ ('# my-select'). val ();
8. Set the value of the radio list
$ ('# My-single-select'). val ('value3 ');
/^ Set the value of the multiple-choice list
$ ('# My-multi-select'). val (['value1', 'value2']);
Like. attr () and. prop ()-, the. val () method can also accept a function as its setter parameter. With this multi-purpose. val () method, you will feel more efficient when using jQuery for Web development.
I hope this article will help you with jQuery programming.