当前位置:网站首页>document.write()的用法-写入文本——修改样式、位置控制
document.write()的用法-写入文本——修改样式、位置控制
2022-07-06 12:51:00 【viceen】
document.write()的用法-写入文本——修改样式、位置控制
1、写入文本
页面加载中可以写入,而不会出现重写页面问题。
语法:document.write(content)
参数:
content:必选。字符串,可以是变量或值为字符串的表达式,写入的内容常常包括HTML标记语言
利用 document.write()来写入文本
<body>
<h1>Head</h1>
<script> document.write('<p>hello document</p>'); </script>
<h2>Tail</h2>
</body>
这是在h1
和h2
之间内嵌一个脚本,使用document.write()来写入一个p
标签。
刷新页面,可以看到最终的结果是
Head
hello document
Tail
即文本在脚本执行的位置被插入。这是因为,浏览器就解析HTML构建DOM的时候,如果遇到script
就会暂停下来,解析script
中的代码并执行,然后再继续解析剩余HTML。(阻塞进行的)
此时再去浏览器中检测DOM的结构,会发现script
与h2
之间多了一个p
,浏览器在解析完h1
之后,碰到script
并执行之,此时document.write
将一段HTML代码写入到文档流中,script执行完毕后,浏览器会解析文档流中的字符串,对新添加的p
标签进行解析。
<script>
var sum_count="Sum:";
document.write("<span>"+sum_count+"</span>")
</script>
<style>
span {
display:inline-block;
width: 30px;
}
</style>
边栏推荐
- 正则表达式收集
- Manifest of SAP ui5 framework json
- 知识图谱之实体对齐二
- Use of OLED screen
- [wechat applet] operation mechanism and update mechanism
- SAP Fiori应用索引大全工具和 SAP Fiori Tools 的使用介绍
- Performance test process and plan
- 监控界的最强王者,没有之一!
- 'class file has wrong version 52.0, should be 50.0' - class file has wrong version 52.0, should be 50.0
- Intel 48 core new Xeon run point exposure: unexpected results against AMD zen3 in 3D cache
猜你喜欢
I've seen many tutorials, but I still can't write a program well. How can I break it?
Pinduoduo lost the lawsuit, and the case of bargain price difference of 0.9% was sentenced; Wechat internal test, the same mobile phone number can register two account functions; 2022 fields Awards an
OLED屏幕的使用
Implementation of packaging video into MP4 format and storing it in TF Card
Activiti global process monitors activitieventlistener to monitor different types of events, which is very convenient without configuring task monitoring in acitivit
Opencv learning example code 3.2.3 image binarization
##无yum源安装spug监控
Manifest of SAP ui5 framework json
硬件开发笔记(十): 硬件开发基本流程,制作一个USB转RS232的模块(九):创建CH340G/MAX232封装库sop-16并关联原理图元器件
OAI 5g nr+usrp b210 installation and construction
随机推荐
Build your own application based on Google's open source tensorflow object detection API video object recognition system (IV)
[diy] how to make a personalized radio
每个程序员必须掌握的常用英语词汇(建议收藏)
Swagger UI tutorial API document artifact
【微信小程序】运行机制和更新机制
Data Lake (VIII): Iceberg data storage format
3D face reconstruction: from basic knowledge to recognition / reconstruction methods!
[weekly pit] output triangle
[DSP] [Part 2] understand c6678 and create project
SAP Fiori应用索引大全工具和 SAP Fiori Tools 的使用介绍
快过年了,心也懒了
Reviewer dis's whole research direction is not just reviewing my manuscript. What should I do?
Comprehensive evaluation and recommendation of the most comprehensive knowledge base management tools in the whole network: flowus, baklib, jiandaoyun, ones wiki, pingcode, seed, mebox, Yifang cloud,
Solution to the 38th weekly match of acwing
Quel genre de programmation les enfants apprennent - ils?
PG基础篇--逻辑结构管理(事务)
Le langage r visualise les relations entre plus de deux variables de classification (catégories), crée des plots Mosaiques en utilisant la fonction Mosaic dans le paquet VCD, et visualise les relation
PHP saves session data to MySQL database
How to turn a multi digit number into a digital list
[wechat applet] operation mechanism and update mechanism