Html,text,val differences

Source: Internet
Author: User

1 first, there are two methods in the HTML attribute, one with an argument, one without2 3 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 an XHTML document, which returns a string4 5 Example:6 7HTML page Code:<div><p>hello</p></div>8 9jquery Code: $ ("Div"). html (); Ten  One Result: Hello A  - 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 -  theHTML page Code:<div></div> -  -jquery Code: $ ("Div"). HTML ("<p>nice to meet you</p>");  -  +Results: [<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 A  at 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. Returned is a string -  - Example: -  -HTML page Code:<p><b>hello</b> fine</p> -  in<p>thank you!</p> -  tojquery Code: $ ("P"). text ();  +  -Results: hellofinethankyou! the  * 2(val): Sets the text content of all matching elements, similar to HTML (), but encodes HTML (the"<"And">"Replace with the corresponding HTML entity). Returns a JQuery object $ Panax NotoginsengHTML page code: <p>test paragraph.</p> -  thejquery Code: $ ("P"). Text ("<b>Some</b> new text.");  +  AResults: [<p><b>Some</b>NewText.</p> ]  the  + 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 JQuery1.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 -  the Example: - Wuyi HTML page code: the Copy the code code as follows: -  Wu<p></p><br/> -<SelectId=" Single"> About<option>Single</option> $<option>Single2</option> -</Select> -<SelectId="multiple"multiple="multiple"> -<option selected="selected">Multiple</option> A<option>Multiple2</option> +<option selected="selected">Multiple3</option> the</Select> -  $jquery Code: $ ("P"). Append ("<b>Single:</b>"+ $("#single"). Val () +"<b>Multiple:</b>"+ $("#multiple"). Val (). Join (", "));  the  theResults: [<p><b>single:</b>single<b>multiple:</b>multiple, Multiple3</p>]  the  the 2. There is a parameter Val (val): Sets the value of each matching element. In JQuery1.2, this can also be a check,Select, Radio element assignment, returns a JQuery object -  inHTML page code: <input type="text"/> the  thejquery Code: $ ("input"). Val ("Hello world!");  About  theResult: Hello world! the  the----------------------------------------------------------------- +  - Summary: the Bayi 1If a drop-down box is <SelectOption Assignment in the > tab, <option name="", value=""></option>Although option has the Value property, the Value property of option on the page is not responsible for displaying on the page, but the text field between the option tags that can actually be displayed on the page. So assigning an option tag to an HTML () method the  the 2. If the <input id="Pro"Name="Province"Value="Anhui Province"The > tag is assigned because the Value property in the input tag is responsible for displaying it on the page, so if you assign a value to the text of the input tag and display the text value on the browser when the browser resolves it, use Val (), attribute.

Html,text,val Differences

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.