<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<ul id="wrap">
<li>
<h6>title</h6>
<p>0</p>
</li>
</ul>
<script>
var list=[
{
title:'title1',
con:'1'
},
{
title:'title2',
con:'2'
},
{
title:'title3',
con:'3'
},
{
title:'title4',
con:'4'
},
{
title:'title5',
con:'5'
},
{
title:'title6',
con:'6'
}
]
var wrap = document.getElementById('wrap');
for(var i = 0; i < list.length; i++){
var copyNode = wrap.children[0].cloneNode(true);
copyNode.children[0].innerHTML = list[i].title;
copyNode.children[1].innerHTML = list[i].con;
wrap.append(copyNode);
}
</script>
</body>
</html>
节点.cloneNode(布尔值)
当布尔值为true时,复制当前节点的所有子孙节点。
当布尔值为false时,只复制当前节点