JS Learning Note (1) document.write () Method Usage Summary

Source: Internet
Author: User

js method document.write (); Used to output content to a browser page
Specific usage:
Used to output string content: document.write ("use double quotes for output string contents");
The value used to output the variable: such as var mynum= "Hello"; document.write (Mynum);
Used to output HTML tag content: such as document.write ("<p> Hello!</p>");
Used to output mixed content, use the "+" sign to connect content: such as document.write (mynum+ "<br/>" + "World");


------------------**********************************----------------------------------
How to use document.write () to output spaces to the browser:
Browser display mechanism, for manual typing of spaces, will be a number of consecutive spaces to display 1 spaces.
such as document.write ("1 2 3");
Output results: 1 2 3
Workaround:
1. Use HTML space tags to solve
such as document.write ("&nbsp;&nbsp;" + "+" + "&nbsp;&nbsp;" + "34");
Output results: 12 34
2. Use CSS styles to resolve
Add "WHITE-SPACE:PRE;" at output The Style property. This style means "blank space will be reserved by the browser";
Such as:
document.write ("<span style= ' white-space:pre; > "+" 1 4 "+" </span> ");
Output results: 1 23 4

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

JS Learning Note (1) document.write () Method Usage Summary

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.