. HTML (),. Text (),. Val () Three methods are used to read the contents of the selected element;
. HTML () is the HTML content used to read the elements (including their HTML tags);
. Text () is used to read the plain text content of an element, including its descendant elements;
. Val () is a value that is used to read the form element's "value".
where the. html () and. Text () methods cannot be used on form elements, while. val () can only be used on form elements;
In addition, when the HTML () method is used on more than one element, only the first element is read;
The. Val () method is the same as. html () and can only read the "value" value of the first FORM element if it is applied on more than one element;
But. Text () is different from theirs, and if. Text () is applied on more than one element, the text content of all the selected elements is read.
1. No parameter HTML (): gets The HTML content of the first matching element. This function cannot be used with XML documents. But it can be used in XHTML documents and returns a string; Eg:hello
2. Parameter HTML (val): Sets the HTML content for each matching element. This function cannot be used with XML documents. But it can be used in XHTML documents. Returns a jquery object; eg:<div><p> Nice to meet you</p></div>
1. No parameter text (): Gets the contents of all matching elements. The result is text that is combined with the text content contained by all matching elements. The return is a string; eg:hellofinethankyou!
2. parameter Text (val): Sets the text content of all matching elements, similar to HTML (), but encodes the HTML (replaces "<" and ">" with the corresponding HTML entity). Returns a JQuery object; eg:& Lt;p><b>some</b> New text.</p>
1. No reference Val (): Obtained The current value of the first matching element. In JQuery 1.2, you can return the value of any element. Includes select. If multiple selections, an array is returned that contains the selected value.
eg: <p><b>Single:</b>Single<b> Multiple:</b>multiple, Multiple3</p>
2. Parameter Val (val): sets the value of each matching element. in jquery 1.2, this can also be assigned a value for the Check,select,radio element, returning a JQuery object eg:hello world!
Returns a string, array
Summary:val ()---is generally used on input, rather than in other elements, to Gets the value of input or select
HTML () and text () can be used on a variety of elements, but HTML () is equivalent to the return of the source code, that is, the returned content will contain a variety of tags, and text () is the equivalent of the page display is returned, the content returned is out of the various tags between the content
The difference between HTML (), Val (), Text ()