DOM ul元素,如何创建呢?
DOM ul element, how to create it?
我在 index.html
有这个元素:
<div id="app"></div>
如何编写查询来获取 DOM 元素?
并创建一个新的 UL 元素并将其附加到前面提到的 <div>
元素?
点赞:
function displayUsers(users) {
// ??????????
};
const ul = document.createElement('ul')
const li = document.createElement('li')
const textNode = document.createTextNode('some text')
li.appendChild(textNode)
ul.appendChild(li)
document.getElementById('app').appendChild(ul)
举个例子
https://www.w3schools.com/jsref/met_node_appendchild.asp
我在 index.html
有这个元素:
<div id="app"></div>
如何编写查询来获取 DOM 元素?
并创建一个新的 UL 元素并将其附加到前面提到的 <div>
元素?
点赞:
function displayUsers(users) {
// ??????????
};
const ul = document.createElement('ul')
const li = document.createElement('li')
const textNode = document.createTextNode('some text')
li.appendChild(textNode)
ul.appendChild(li)
document.getElementById('app').appendChild(ul)
举个例子 https://www.w3schools.com/jsref/met_node_appendchild.asp