当前位置:网站首页>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
边栏推荐
- 数据清洗 ETL 工具Kettle的安装
- GoLand debug go use - white record
- Kettle experiment
- MySQL of database -- overview and installation
- Three challenges that a successful Devops leader should be aware of
- Operation not allowed for a result set of type resultset TYPE_ FORWARD_ ONLY. Explain in detail
- Thread scheduling (priority)
- ATSS(CVPR2020)
- Go language learning notes - array | go language from scratch
- 108. Convert an ordered array into a binary search tree
猜你喜欢
Failed to download esp32 program, prompting timeout
[SQL Server fast track] view and cursor of database
Machine learning (VI) -- Bayesian classifier
kernel-pwn学习(4)--Double Fetch&&0CTF2018-baby
Open services in the bottom bar of idea
三、6【Verilog HDL】基础知识之门级建模
A must see wechat applet development guide 1 - basic knowledge
DVWA range practice
nn. Explanation of module class
数据清洗 ETL 工具Kettle的安装
随机推荐
Distributed message oriented middleware framework selection - Digital Architecture Design (7)
数据清洗 ETL 工具Kettle的安装
Using JS to realize a thousandth bit
Buuctf [actf2020 freshman competition] include1
基于ThinkPHP5版本TRC20-资金归集解决方案
Go language learning notes - exception handling | go language from scratch
Summary of wrong questions 1
Flutter 的加载动画这么玩更有趣
MySQL - Chapter 1 (data type 2)
A must see wechat applet development guide 1 - basic knowledge
Simple understanding of arguments in JS
nn. Explanation of module class
Redis Desktop Manager for Mac
Number theory to find the sum of factors of a ^ B (A and B are 1e12 levels)
Pre parsing of JS
[boutique] using dynamic agent to realize unified transaction management II
Open services in the bottom bar of idea
Kettle experiment
Sql1 [geek challenge 2019]
考研线性代数常见概念、问题总结