Js用forEach语法循环列表

2020-09-03 10:34:10 浏览数 (2)

代码语言:javascript复制
 <div class="box"></div>
 <script>
    var list = [{ name: 'aa', title: 'bb' }, { name: 'cc', title: 'dd' }, { name: 'ee', title: 'ff' }]
    var more = ''
    list.forEach(function (i) {
        more  = `  <div class="item">
            <span>${i.name}</span>
            <span>${i.title}</span>
        </div>`
    })
    $('.box').append(more)
</script>

0 人点赞