当前位置:网站首页>JS DOM learn three ways to create elements
JS DOM learn three ways to create elements
2022-04-23 09:27:00 【Small white egg tart】
document.write() understand
Write content directly to the document stream of the page , But the document flow is finished , Will cause the page to redraw , Recreate a new page , Only the newly written element , Only div After execution
var btn = document.querySelector('button');
btn.onclick = function() {
document.write('<div>123</div>');
}
innerHTML
It's more efficient to create multiple elements ( Don't take concatenated strings , Take the form of array )
var d1 = +new Date();
var inner = document.querySelector('.inner');
// for (var i = 0; i <= 100; i++) {
// inner.innerHTML += '<a href="#"> Baidu </a>';
// } Time 21 This is the way to splice strings
var arr = [];
for (var i = 0; i <= 100; i++) {
arr.push('<a href="#"> Baidu </a>');
} // improvement Array 2
inner.innerHTML = arr.join('');
// var create = document.querySelector('.create');
// for (var i = 0; i <= 100; i++) {
// var a = document.createElement('a');
// a.innerHTML = ' Better than ';
// create.appendChild(a);
// } // Time 2 Efficient
document.createElement()
After creating the node , Then indicate where to add it
版权声明
本文为[Small white egg tart]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230624113877.html
边栏推荐
- What is augmented reality technology? Where can it be used?
- Employee probation application (Luzhou Laojiao)
- Brush classic topics
- To remember the composition ~ the pre order traversal of binary tree
- MYCAT configuration
- Pre parsing of JS
- Write down the post order traversal of the ~ binary tree
- 数据清洗 ETL 工具Kettle的安装
- 108. Convert an ordered array into a binary search tree
- How to render web pages
猜你喜欢

Kettle experiment (III)

SAP 101K 411k inventory change

Unfortunately, I broke the leader's confidential documents and spit blood to share the code skills of backup files

Kettle experiment

nn. Explanation of module class

Chapter VIII project stakeholder management of information system project manager summary

Matlab draw five-star red flag

Flink SQL realizes the integration of stream and batch

阿里云架构师解读四大主流游戏架构

Installation of data cleaning ETL tool kettle
随机推荐
Go language learning notes - exception handling | go language from scratch
Production practice elk
个人主页软件Fenrus
搞不懂时间、时间戳、时区,快来看这篇
Using JS to realize a thousandth bit
DJ music management software pioneer DJ rekordbox
Matlab draw five-star red flag
kettle实验
How to read excel table to database
Creation of raid0 and RAID5 and Simulation of how RAID5 works
Set the maximum width of the body, but why does the background color of the body cover the whole page?
成功的DevOps Leader 应该清楚的3个挑战
To remember the composition ~ the pre order traversal of binary tree
Number of islands
Two methods of building Yum source warehouse locally
npm ERR! network
小女孩行走
112. 路径总和
ATSS(CVPR2020)
Leetcode-199 - right view of binary tree