题解 | #列表动态渲染#
列表动态渲染
https://www.nowcoder.com/practice/347e2e88f11a4b0c89157568f26ea126
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> </head> <body> <ul></ul> <script> var people = [ { name: '牛油1号', id: 1, age: 20 }, { name: '牛油2号', id: 2, age: 21 }, { name: '牛油3号', id: 3, age: 19 }, ] var ul = document.querySelector('ul'); // 补全代码 for(let i = 0;i<people.length;i++) { var txt = people[i].name + ' ' + people[i].age + '岁'; var li = document.createElement('li'); li.innerHTML = txt; ul.append(li); } </script> </body> </html>