这样可以吗?
var div = document.getElementById("wrap");
var ul = document.createElement("ul");
var count = ["HTML","CSS","HTML5","CSS3"];
for(var i=0;i<4;i++){
var li = document.createElement("li");
li.className="li"+i;
li.appendChild(document.createTextNode(count[i]));
ul.appendChild(li);
}
var a = wrap.replaceChild(ul,list);
82
收起
正在回答 回答被采纳积分+1
3回答
nkliyc
2019-12-05 10:27:02
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>节点练习</title>
</head>
<body>
<div id="wrap">
<ul id="list">
<li>第一个li</li>
<li>第二个li</li>
<li>第三个li</li>
</ul>
</div>
<script>
//在此处补充代码 function createListItems(items) { var ul = document.createElement('ul') for (var i = 0, len = items.length; i < len; i++) { var li = document.createElement('li') var text = document.createTextNode(items[i]) li.appendChild(text) ul.appendChild(li) } return ul } var items = ['HTML', 'CSS', 'HTML5', 'CSS3'] var newList = createListItems(items) var list = document.getElementById('list') var wrap = document.getElementById('wrap') wrap.replaceChild(newList, list) </script>
</body>
</html>
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星