当前位置:网站首页>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
边栏推荐
- web页面如何渲染
- A must see wechat applet development guide 1 - basic knowledge
- LeetCode396. Rotate array
- MySQL小練習(僅適合初學者,非初學者勿進)
- JS prototype chain
- Installation of data cleaning ETL tool kettle
- How to protect open source projects from supply chain attacks - Security Design (1)
- Applet error: should have URL attribute when using navigateto, redirectto or switchtab
- [boutique] using dynamic agent to realize unified transaction management II
- Base de la technologie électronique numérique 3.1 aperçu du circuit de porte, 3.2 circuit de porte à diode semi - conductrice
猜你喜欢
JSON input of Chapter 14 of kettle paoding jieniu
Go language learning notes - structure | go language from scratch
MySQL of database -- overview and installation
《数字电子技术基础》3.1 门电路概述、3.2 半导体二极管门电路
[in-depth good article] detailed explanation of Flink SQL streaming batch integration technology (I)
Yyds dry goods inventory ubuntu18 0.4 install MySQL and solve error 1698: access denied for user ''root' '@' 'localhost' '
MySQL of database -- Fundamentals
Kettle experiment
501. Mode in binary search tree
Leetcode题库78. 子集(递归 c实现)
随机推荐
web页面如何渲染
三、6【Verilog HDL】基础知识之门级建模
First principle mind map
npm ERR! network
Write down the post order traversal of the ~ binary tree
基于ThinkPHP5版本TRC20-资金归集解决方案
How to read excel table to database
What is augmented reality technology? Where can it be used?
Leetcode0587. 安装栅栏(difficult)
ALV tree (ll LR RL RR) insert delete
考研线性代数常见概念、问题总结
Summary of wrong questions 1
Open services in the bottom bar of idea
js 原型链的深入
Number of islands
Data visualization: use Excel to make radar chart
112. 路径总和
Applet error: cannot read property'currenttarget'of undefined
Flutter 的加载动画这么玩更有趣
MySQL - Chapter 1 (data type 2)