In jquery.html (), HTML tags are used to read and modify elements ,. text () is used to read or modify the plain text content of an element ,. val () is used to read or modify the value of a form element.
1. HTML
Html (): gets the html content of the First Matching Element. This function cannot be used in XML documents. But it can be used in XHTML documents.
Html (val): sets the html content of each matching element. This function cannot be used in XML documents. But it can be used in XHTML documents.
2. TEXT
Text (): Get the content of all matching elements.
The result is a combination of text content contained by all matching elements. This method is effective for both HTML and XML documents.
Text (val): Set the text content of all matching elements.
Similar to html (), but the encoding HTML (replace "<" and ">" with the corresponding HTML Entity ).
3. VAL
Val (): obtains the current value of the First Matching Element.
Val (val): sets the value of each matching element.
The above content is copied in the help document of JQuery, and it is not nonsense. Below are some exercises you have made. The Code is as follows:
During the exercises, I found another difference between html and text.
When html () is used to remove the content of an element, the format below the selected element can also be obtained.
For example:
Write Less Do More
If we use var strHTML = $ ("# pShow" ).html,
The result is:Write Less Do More
If var strHTML2 = $ ("# pShow B I" ).html (); is used
The result is Write Less Do More.
Text does not have the first case,
If var strText = $ ("# pShow"). text ();
The result is Write Less Do More.
<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% String path = request. getContextPath (); String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/"; %>