. val () and. AddClass ()
1. Val () is used to process the values of form elements, such as input, select, and textarea
2. Val () 3 Ways
. val () No parameter, gets the current value of the first element in the matching element collection
. val (value) sets the value of each element in the matching element collection
. val (function) returns the set of functions
3 through . Val () handles the Select element, when no selection is selected, he returns null
4 . Val () method is used to set the value of the field of the form
5 If the Select element has a multiple (multiple selection) attribute and at least one option is selected, the. Val () method returns an array that contains the values of each selected selection
6. Summary of differences between HTML (),. Text (), and. Val ()
. HTML (),. Text (), and. Val () Three methods are used to read the contents of the selected element, except that. html () is used to read the elements of the HTML content (including HTML tags),. Text () is used to read the plain text content of the element, including its descendant elements. Val () is the value that is used to read the form element
The. htm () and. Text () methods cannot be used on form elements, while. val () can only be used on form elements
The. HTML () method is used on more than one element, only the first element is read, and the. Val () method is the same as the. html ()
If it is applied on more than one element, only the value of the first FORM element can be read, but. Text () is not the same as they are, if. Text () is applied on more than one element, the textual content of all the selected elements is read
. HTML (htmlstring),. Text (TextString), and Val (value) Three methods are used to replace the contents of the selected element, and if three methods are applied to multiple elements simultaneously, the contents of all selected elements will be replaced
. HTML (),. Text (), and. Val () can use the return value of the callback function to dynamically change the contents of multiple elements
7 in the HTML structure, multiple classes are separated by spaces, and when a node ( or a label ) contains multiple classes, the ClassName property of the DOM element response gets an array that is not a class name, but a string that contains spaces
8. AddClass () method for dynamically increasing class names
9 . 2 ways to AddClass ()
. addclass (className) One or more style names to add for each matching element
. addclass (function (index,currentclass)) This function returns one or more of the style names to be added separated by spaces
The AddClass () method does not replace a style class name, but simply adds a style class name to the element
11 How to add a newclass style to the P element
such as <p class= "Orgclass" >
$ ("P"). Assclass ("Newclass")
The class of P element is actually class= "Orgclass Newclass" style will only continue to increase on the original class, separated by a space
The jquery attribute is ——. val () and the style is added. AddClass ()