js document.write() usage introduction_javascript skills
After loading the page, the browser output stream is automatically closed; after that, any document.write() method that operates on the current page will open a new output stream. It will clear the current page content (including any variables or values from the source document), so. If you want to replace the current page with HTML generated by a script, you must concatenate the HTML content and assign it to a variable and use a document.write() method to complete the writing operation. You do not have to clear the document and open a new data stream. A document.write() ) can be called to complete all operations.
One more thing to note about the document.write() method is its related method document.close(). After the script finishes writing content to the window (whether it is this window or another window). The output stream must be closed. After the last document.write() method of the delay script. You must ensure that the document.close() method is included, otherwise pictures and forms will not be displayed. Also, any subsequent calls to the document.write() method will only append the content to the page, but will not clear the existing content to write new values.
document.write method
One of the most basic JavaScript commands is document.write. This command simply prints the specified text content to the page. To print text verbatim, add single quotes around the printed text string.
document.write('Hello World!');
The above js code will display "Hello World!" on the page
You can use document.write to print variables. Enter the variable name without quotation marks, as follows:
var mytext = "Hello again";
document .write(mytext);
Note: If the variable name is enclosed in quotes, the variable name will be printed (the variable value will not be printed). You can use the " " symbol to concatenate variable values and text strings.
var color1 = "purple";
var color2 = "pink";
document.write('
colour1: ' colour1 '
colour2: ' colour2 '
The print result is as follows:
colour1: purple
colour2: pink
document.write is also mostly used to load js ads
document.write('
document.write("
document.write("
Generally, single quotes (double quotes) are used to connect characters outside, and double signals (single quotes) are used inside, so that there is no mistake. Of course, you can also use escape characters, but this will be more troublesome to modify later.
The js loaded in document.write is asynchronous
');
}
load("http://www.jb51.net/js/2011/jquery-1.5.1.min.js");
// write("http://www.jb51.net/js/2011/jquery-1.5.1.min.js");
<script><br>alert($);<br></script>
问: 用createElement("script")的方式加载,调用函数就会报错,用document.write就不报错?
答案:
对于动态创建的js 引用而言 ,针对不同的浏览器有不同的反应
楼主的这种写法 对 FF Opera 而言 load 方法是阻塞的 故alert($)能输出,而对IE Chrome Safria 而言 是非阻塞的 所以就会报错
而document.write的方式,对所有浏览器而言都是阻塞的 即同步的 所以alert($)会输出正确结果

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Face detection and recognition technology is already a relatively mature and widely used technology. Currently, the most widely used Internet application language is JS. Implementing face detection and recognition on the Web front-end has advantages and disadvantages compared to back-end face recognition. Advantages include reducing network interaction and real-time recognition, which greatly shortens user waiting time and improves user experience; disadvantages include: being limited by model size, the accuracy is also limited. How to use js to implement face detection on the web? In order to implement face recognition on the Web, you need to be familiar with related programming languages and technologies, such as JavaScript, HTML, CSS, WebRTC, etc. At the same time, you also need to master relevant computer vision and artificial intelligence technologies. It is worth noting that due to the design of the Web side

How to use JS and Baidu Map to implement map pan function Baidu Map is a widely used map service platform, which is often used in web development to display geographical information, positioning and other functions. This article will introduce how to use JS and Baidu Map API to implement the map pan function, and provide specific code examples. 1. Preparation Before using Baidu Map API, you first need to apply for a developer account on Baidu Map Open Platform (http://lbsyun.baidu.com/) and create an application. Creation completed

Essential tools for stock analysis: Learn the steps to draw candle charts in PHP and JS. Specific code examples are required. With the rapid development of the Internet and technology, stock trading has become one of the important ways for many investors. Stock analysis is an important part of investor decision-making, and candle charts are widely used in technical analysis. Learning how to draw candle charts using PHP and JS will provide investors with more intuitive information to help them make better decisions. A candlestick chart is a technical chart that displays stock prices in the form of candlesticks. It shows the stock price

How to use PHP and JS to create a stock candle chart. A stock candle chart is a common technical analysis graphic in the stock market. It helps investors understand stocks more intuitively by drawing data such as the opening price, closing price, highest price and lowest price of the stock. price fluctuations. This article will teach you how to create stock candle charts using PHP and JS, with specific code examples. 1. Preparation Before starting, we need to prepare the following environment: 1. A server running PHP 2. A browser that supports HTML5 and Canvas 3

Overview of how to use JS and Baidu Maps to implement map click event processing: In web development, it is often necessary to use map functions to display geographical location and geographical information. Click event processing on the map is a commonly used and important part of the map function. This article will introduce how to use JS and Baidu Map API to implement the click event processing function of the map, and give specific code examples. Steps: Import the API file of Baidu Map. First, import the file of Baidu Map API in the HTML file. This can be achieved through the following code:

How to use JS and Baidu Maps to implement the map heat map function Introduction: With the rapid development of the Internet and mobile devices, maps have become a common application scenario. As a visual display method, heat maps can help us understand the distribution of data more intuitively. This article will introduce how to use JS and Baidu Map API to implement the map heat map function, and provide specific code examples. Preparation work: Before starting, you need to prepare the following items: a Baidu developer account, create an application, and obtain the corresponding AP

With the rapid development of Internet finance, stock investment has become the choice of more and more people. In stock trading, candle charts are a commonly used technical analysis method. It can show the changing trend of stock prices and help investors make more accurate decisions. This article will introduce the development skills of PHP and JS, lead readers to understand how to draw stock candle charts, and provide specific code examples. 1. Understanding Stock Candle Charts Before introducing how to draw stock candle charts, we first need to understand what a candle chart is. Candlestick charts were developed by the Japanese

The relationship between js and vue: 1. JS as the cornerstone of Web development; 2. The rise of Vue.js as a front-end framework; 3. The complementary relationship between JS and Vue; 4. The practical application of JS and Vue.
