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

May 16, 2016 pm 05:26 PM
Location style

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.
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Win11 startup path and how to open it Win11 startup path and how to open it Jan 03, 2024 pm 11:13 PM

Win11 startup path and how to open it

Details on how to turn on environment variable settings on Windows 11 Details on how to turn on environment variable settings on Windows 11 Dec 30, 2023 pm 06:07 PM

Details on how to turn on environment variable settings on Windows 11

where is windows10 credential manager where is windows10 credential manager Jul 09, 2023 am 10:09 AM

where is windows10 credential manager

macOS: How to change the color of desktop widgets macOS: How to change the color of desktop widgets Oct 07, 2023 am 08:17 AM

macOS: How to change the color of desktop widgets

Understand the location and structure of pip installation package storage Understand the location and structure of pip installation package storage Jan 18, 2024 am 08:23 AM

Understand the location and structure of pip installation package storage

How to change the location of Gaode Map Home How to change the location of Gaode Map Home Feb 27, 2024 pm 07:31 PM

How to change the location of Gaode Map Home

Where is Kuaishou published and how to change its location? How to add a location to a video that has been uploaded? Where is Kuaishou published and how to change its location? How to add a location to a video that has been uploaded? Mar 21, 2024 pm 06:00 PM

Where is Kuaishou published and how to change its location? How to add a location to a video that has been uploaded?

Location of Origami Bird at Stardome Railway Crocker Film and Television Park Location of Origami Bird at Stardome Railway Crocker Film and Television Park Mar 27, 2024 pm 11:51 PM

Location of Origami Bird at Stardome Railway Crocker Film and Television Park

See all articles