当前位置:网站首页>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
边栏推荐
- Mini - exercice MySQL (seulement pour les débutants, pas pour les non - débutants)
- Brush classic topics
- Go language learning notes - slice, map | go language from scratch
- Give the method of instantiating the object to the new object
- Cloud computing competition -- basic part of 2020 competition [task 3]
- ALV tree (ll LR RL RR) insert delete
- On array replication
- Is Zhongyan futures safe and reliable?
- ASUS laptop can't read USB and surf the Internet after reinstalling the system
- How to render web pages
猜你喜欢

Brush classic topics

EmuElec 编译总结

Harbor enterprise image management system

Kettle实验 转换案例

501. Mode in binary search tree

Mini - exercice MySQL (seulement pour les débutants, pas pour les non - débutants)
![Sql1 [geek challenge 2019]](/img/ad/afca09bc1da003393319af700e90e3.png)
Sql1 [geek challenge 2019]

I don't understand time, timestamp and time zone. Look at this article

A must see wechat applet development guide 1 - basic knowledge

ATSS(CVPR2020)
随机推荐
Enter "net start MySQL" and "system error 5. Access denied" appears. Detailed explanation of the problem
Flutter 的加载动画这么玩更有趣
NPM installation yarn
Single sign on SSO
Your guide to lowering your cholesterol with TLC (continuously updated)
Get trustedinstaller permission
Give the method of instantiating the object to the new object
JS prototype chain
GUI, CLI and UNIX Philosophy
Node installation
Colorui solves the problem of blocking content in bottom navigation
MySQL of database -- basic common query commands
Data visualization: use Excel to make radar chart
Kettle experiment (III)
I don't understand time, timestamp and time zone. Look at this article
DVWA range practice
kernel-pwn学习(3)--ret2user&&kernel ROP&&QWB2018-core
How to read excel table to database
501. 二叉搜索树中的众数
Applet error: cannot read property'currenttarget'of undefined