author Zhao Xiao mission 1:0 Basic JavaScript Coding (i)
2809 2017-03-02 10:49
First, JS in innerHTML, outerHTML, InnerText, outertext, value of the difference and contact?
JS Sets or gets the value of the selection:
①innerhtml: Property Sets or returns the HTML within the tag. That is, the entire contents of the object from its starting position to the terminating position, including the HTML tag.
②outerhtml: Property Sets or returns the HTML within the label and tag. That is, the entire contents of the object from the beginning of the tag to the terminating position, including the HTML tag.
If you want to output content that does not contain HTML tags, you can use innerHTML to get content that contains HTML tags, and then use regular expressions to remove HTML tags,
③innetext: From the start position to the end position, but it removes the HTML tags. (can only be used under IE and chrome)
④outertext settings (including labels) or get (excluding tags) the text <br><br> of the object;
⑤value: property to set or return the default value for the password field. Gets the value of the text box
Two, text () in jquery, HTML (), and Val ()
in jquery set or get the value of the selection:
①text (); Sets or gets the text content of the selected element;
②html (); Sets or gets the contents of the selected element (including HTML tags);
③val (); Sets or gets the value of a form field (provided that the form has the Value property set);
First, there are two methods in the HTML attribute, one with a parameter, and one without a parameter
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 example: HTML page code: <div><p> Hello</p></div> jquery Code: $ ( "div"). html (); Result: <p>hello</p> 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 HTML page code: <div></div> jquery Code: $ ( Span class= "hljs-string" > "div"). html ( "<p>nice to meet you</p>"); Result: [<div><p> Nice to meet You</ P></div>]
Second, there are two methods in the Text property, one with a parameter, one without a parameter
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 example: HTML page code:<p><b>hello</b > Fine</p> <p>thank you! </p> jquery Code: $ ( "P"). text (); Result: hellofinethankyou! 2. Parameter text (val): Sets the text content of all matching elements, similar to HTML (), but encodes HTML ( ">" is replaced with the corresponding HTML entity. Returns a jquery object HTML page code: <p>test Paragraph. </p> jquery Code: $ ( "P"). Text ( " <b>Some</b> new text. "); Result: [<p><b>some</b > new text. </p>]
Finally, there are two methods in the Val () attribute, one with a parameter and one without a parameter.
1. No parameter Val (): Gets 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. Returns a string, array
jquery Code: $ ("P"). Append ("<b>Single:</b>" + $ ("#single"). Val () + "<b>Multiple:</b>" + $ ("# Multiple "). Val (). Join (", "));
Results: [<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
HTML page code: <input type= "text"/>
jquery Code: $ ("input"). val ("Hello world!");
Result: Hello world!
*
JS in innerHTML, outerHTML, InnerText, outertext, value of the difference and contact? Text (), HTML (), and Val () in jquery?