<!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>
<h1>动态创建列表</h1>
<div id="box">
</div>
<script>
var box = document.getElementById("box");
var names = ["刘备","曹操","孙权","关羽"];
//创建ul
var ul = document.createElement("ul");
box.appendChild(ul);
//向ul中添加数据
for(var i=0;i<names.length;i++){
var li = document.createElement("li");
ul.appendChild(li);
//给每个li添加内容
li.innerText = names[i];
}
</script>
</body>
</html>