2

#yyds干货盘点# 前端歌谣的刷题之路-第八十五题-列表动态渲染

 1 year ago
source link: https://blog.51cto.com/u_14476028/5691007
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

#yyds干货盘点# 前端歌谣的刷题之路-第八十五题-列表动态渲染

精选 原创

我是歌谣 我有个兄弟 巅峰的时候排名c站总榜19 叫前端小歌谣 曾经我花了三年的时间创作了他 现在我要用五年的时间超越他 今天又是接近兄弟的一天人生难免坎坷 大不了从头再来 歌谣的意志是永恒的 放弃很容易 但是坚持一定很酷 本题目源自于牛客网 微信公众号前端小歌谣

请补全JavaScript代码,将预设代码中的"people"数组渲染在页面中。实现下面的列表:

  • 牛油1号 20岁
  • 牛油2号 21岁
  • 牛油3号 19岁
#yyds干货盘点# 前端歌谣的刷题之路-第八十五题-列表动态渲染_html
编辑
<!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>列表动态渲染</title>
</head>

<body>
<!-- 请补全JavaScript代码,将预设代码中的"people"数组渲染在页面中。实现下面的列表:

牛油1号 20岁
牛油2号 21岁
牛油3号 19岁 -->
<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');

let dom = '';
for(let i=0; i<people.length; i++){
dom += '<li>'+people[i].name+people[i].age+'岁</li>'
}
ul.innerHTML = dom
// 补全代码</script>
</body>

</html>

类似于低八十二题 利用dom直接create和innerHtml赋值

  • 1
  • 收藏
  • 评论
  • 分享
  • 举报

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK