Document. write () and style and location control of output content _ javascript skills

Source: Internet
Author: User
Document. write () is used to simply print the content to the page and print the content you need literally. Since you can output the variable, you will definitely want to control the display of the variable, for example, one of the most basic commands in position and style JS: document. write (), used to print the content to the page, you can print the content you need-document. write ("content"). Here, content is the content to be output. Of course, there is another situation where the content in JS needs to be output, such as variables, and so on. Therefore, document must be used. write (+ variable); of course, variable is the variable you want to output.

Since variables can be output, you certainly want to control the display of variables, such as positions and styles. The first control method is to add a style inside the application, such

Document. write ("= font-size: 20px; font-family = Helvetica;" content "", but if there are too many styles to be added, it will not only look bloated, it is not easy to modify.

In this case, it is certainly better to use the selector. However, because you need to use various double quotation marks (single quotation marks) when using the selector, you should avoid early matching between double quotation marks and single quotation marks, the method I want to avoid is to use \ "to remind the browser to avoid premature matching, for example:

Document. write ("

"+ Percentage +"

");

An ID selector named OK is defined here to control the style. Because the id name needs to be enclosed in double quotation marks, to avoid matching with the double quotation marks, use \ "to declare it, then in the CSS file

# OK {style ;}

You can define the style and position you want.
Related Article

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.