Home >Web Front-end >JS Tutorial >A brief discussion on document.write() output style_javascript skills

A brief discussion on document.write() output style_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:00:231688browse

One of the most basic commands in js: document.write(), used to simply print content onto the page. You can print the content you need verbatim - document.write("content"), here content It is the content that needs to be output; of course there is also a situation where you need to output changes in JS such as variables, etc., then you need to use document.write(variable); of course variable is the variable you want to output.

Since you can output variables, you will definitely want to control the display of variables, such as position and style. The first control method is to add styles inside the application, such as

Copy code The code is as follows:
document.write("f58d879913bf7db659b590c4ee939567 =font-size:20px;font-family= Helvetica;"content"e6e38b3c62e8df885fe2e3986461aa63"

If there are too many styles that need to be added, it will not only look bloated, but it will also be inconvenient to modify.

In this case, it will definitely feel better to use a selector. However, since you need to use various double quotes and single quotes when using selectors, you should pay attention to preventing early matching of double quotes and single quotes when using them. The way I avoid this is to use " to remind the browser not to match prematurely. , examples are as follows:

document.write("<div id=\"ok\">"+percentage+"</div>");

An ID selector named ok is defined here to control the style. Since the id name needs to be enclosed in double quotes, in order to avoid matching the previous double quotes, use " to declare it, and then in the CSS file Inside

#ok{style;}

You can then define the style and position you want.

The above is the entire content of this article, I hope you all like it.

Statement:
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