方式一:使用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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。