2 回答
TA贡献1906条经验 获得超3个赞
<!DOCTYPE html>
<html>
<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>Document</title>
<script>
main = () => {
const arr = [1, 2, 3, 4];
const list = arr.map(item => {
const node = document.createElement('span');
node.innerHTML = item * 2;
node.style.margin = '20px';
return node;
});
list.forEach(element => {
document.getElementById("target").appendChild(element)
})
}
</script>
</head>
<body onload="main()">
<div id="target"></div>
</body>
</html>
添加回答
举报