Brief introduction to document. write of output style

  • 2020-06-07 03:59:02
  • OfStack

One of the most basic commands in js is document.write (), which is used to simply print the content to the page. You can print verbatim what you need -- document.write ("content"). Of course, there is also a case where you need to output something in JS, such as variable, etc., then you need to use document.write (+variable); variable, of course, is the variable you want to output.

Since you can output variables, you will want to control their display, such as location and style. The first control method is to apply the method of adding styles internally, such as

document.write("<font size="+0">=font-size:20px;font-family= Helvetica;"content"</font>"

If too many styles need to be added, it will not only look bloated, but it will not be easy to change.

In this case, the selector is definitely going to feel better. However, because the selector is used to use all kinds of double quotation marks and single quotation marks, it should be careful to prevent the early matching of double quotation marks and single quotation marks. I avoid using \" to remind the browser not to match early.


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

An ID selector named ok is defined to control the style. Since the id name needs to be enclosed in double quotation marks, to avoid matching the previous double quotation marks, declare it with \" 1 in the CSS file


#ok{style;}

You can define the style and location you want.

This is the end of this article, I hope you enjoy it.


Related articles: