Home > Web Front-end > JS Tutorial > Example of using document.write to output content to the page in JavaScript_javascript skills

Example of using document.write to output content to the page in JavaScript_javascript skills

WBOY
Release: 2016-05-16 16:33:45
Original
1450 people have browsed it

The document.write command outputs text to the page

This example uses JavaScript’s document.write command to output the specified text to the page. The code is as follows:

Copy code The code is as follows:



Save the above code as write.html (or write.htm) using a text editor. Double-click write.html to run it (actually use a browser such as IE to open this file), and you will see the following text on the page:

Copy code The code is as follows:
I am outputting text to the page!

Tips

If you use IE browser and it prompts: "To help protect security, Internet Explorer has restricted this webpage from running scripts or ActiveX spaces that can access your computer." Then please select "Allow blocked content" to allow IE browsing The server runs the above JavaScript code.

document.write outputs text with html tags to the page

If the text output to the page has an html tag, you only need to include the tag in the output text:

Copy code The code is as follows:


Explanation of syntax with examples

Similar to the previous "JavaScript Pop-up Prompt Box Example", document.write is a standard JavaScript syntax command used to output a specified string to a Web page. The characters to be output are enclosed in "" or '' and placed into document.write().

The document.write command and pop-up box command alert used in this example will be frequently used in future JavaScript learning, so be sure to use them skillfully.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template