通过``符号直接把标签放进去,就不用字符串拼接了,然后再通过${comment.img1},这种形式渲染数据
<script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
方法1
<ul id="brand_slide_ul5"></ul> <script type="text/javascript" src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> var html = ''; var data = [] $.each(data, function(commentIndex, comment) { html += `<li data-k="${comment.id}"> <img class="lazy_img" data-original="${comment.img1}"/> <p>${comment.name}</p> </li>` }); $('#brand_slide_ul5').html(html); </script>
方法2
<div class='zpInfoShow'></div>
$.each(
data,
function(index, item) {
var str = '';
str += '<div class="zpxxList" >'
+ '<a href="' + item.URL+ '"><div class="zpOneName" id="'
+ ('zpInfo' + item.ID)
+ '"><span>'
+ (item.GIFT_NAME).substr(0,1)
+ '</span></div></a>'
+ '</div>'
$('.zpInfoShow').append(str);
})