Common JS output methods (5) and js output methods

Source: Internet
Author: User

Common JS output methods (5) and js output methods

I can work for you without much nonsense. The details are as follows:

1. alert ("content to be output ");

-> A dialog box is displayed in the browser, and the content to be output is displayed.

-> Alert converts the content to be output to a string and then

2. document. write ("content to be output ");

-> Directly display the output content on the page

3. console. log ("content to be output ");

-> Output content on the console

4. value-> assign values to the text box (Form element)

-> Get the content of the text box (Form element)

Document. getElementById ("search"). value = "content to be added to the # search text box ";

5. innerHTML/innerText-> assign values to tags except form elements

Document. getElementById ("div1"). innerHTML = "alright ";
Document. getElementById ("div1"). innerText = "alright ";

-> Differences Between innerHTML and innerText

1) When innerHTML is assigned a value, if a valid HTML Tag is processed as a real tag, the tag can play its own role;

InnerText whether or not labels are assigned values as text, all the values are text, and tags do not play their own role;

(When assigning values, innerHTML can recognize HTML tags, but innerText cannot)

2) innerText is not supported in some Firefox browsers, while innerHTML is supported by all browsers.

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.