您好,登錄后才能下訂單哦!
方式一:使用innerHTML拼接字符串方式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>innerHTML拼接字符串方式</title>
<style>
div {
width: 1000px;
}
</style>
<script>
window.onload = function() {
var div = document.querySelector('div');
var time1 = +new Date();
for (var i = 0; i < 1000; i++) {
div.innerHTML += '<a href="javaScript:;">鏈接</a>\t';
}
var time2 = +new Date();
console.log(time2 - time1);
}
</script>
</head>
<body>
<div></div>
</body>
</html>
運行結果:
方式二:innerHTML加數組的方式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>innerHTML加數組的方式</title>
<style>
div {
width: 1000px;
}
</style>
<script>
window.onload = function() {
var div = document.querySelector('div');
var arr = [];
var time1 = +new Date();
for (var i = 0; i < 1000; i++) {
arr.push('<a href="javaScript:;">鏈接</a>\t')
}
div.innerHTML = arr.join('');
var time2 = +new Date();
console.log(time2 - time1);
}
</script>
</head>
<body>
<div></div>
</body>
</html>
運行結果:
方式三:createElement方式
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>createElement方式</title>
<style>
div {
width: 1000px;
}
</style>
<script>
window.onload = function() {
var div = document.querySelector('div');
var time1 = +new Date();
for (var i = 0; i < 1000; i++) {
var a = document.createElement('a');
a.innerHTML = '鏈接';
a.href = 'javaScript:;';
div.appendChild(a);
}
var time2 = +new Date();
console.log(time2 - time1);
}
</script>
</head>
<body>
<div></div>
</body>
</html>
運行結果:
總結:
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。