Home > Web Front-end > JS Tutorial > document.write() and its output content style and position control_javascript skills

document.write() and its output content style and position control_javascript skills

WBOY
Release: 2016-05-16 17:26:00
Original
1939 people have browsed it

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 word for word - document.write("content"), where content is what needs to be output. content; of course there is another 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

document.write("=font-size:20px;font-family= Helvetica;"content"" like this, However, if there are too many styles to be added, it will not only appear bloated, but also inconvenient to modify.

In this case, it will definitely feel better to use a selector. Various double quotes and single quotes are used, so when using them, attention should be paid to preventing early matching of double quotes and single quotes. The way I avoid it is to use " to remind the browser not to match prematurely. The example is as follows:

document.write("

" percentage "
");

Here defines an ID selector named ok to control the style, because the id name needs to be enclosed in double quotes , so in order to avoid matching the previous double quotes, use " to declare it, and then in the CSS file

#ok{style;}

you can define what you want Style and location too.
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