<script type='text/html' id='tpl-users'>
           {{each list val}}
           <p class='headline'>{{val.title}}</p>
           <p class='hei'>
            <span>{{val.aut_name}}</span>
            <span>{{val.pubdate}}</span>
           </p>
           {{/each}}
    </script>
<p>function news(id) {
let data = new Date()
$.ajax({
type: 'GET',
url: 'http://toutiao.itheima.net/v1_0/articles?channel_id=' + id + '&amp;timestamp=' + data,
success: function (res) {
// 筛选数据
const { results } = res.data;
console.log(48, results);
// 调用template函数
let htmls = template('tpl-users', { list: results })
//渲染数据到页面
$('#title').html(htmls)
// 遍历images
results.forEach(result =&gt; {
const { images } = result.cover;
// 判断images的length为3是当前img的width为30%
if (images.length === 3) {
$('img').css('width', '30%');
}
// 判断images的length为1是当前img的width为100%
if (images.length === 1) {
$('img').css('width', '100%');
}
});
}
})
}</p>

原文地址: https://www.cveoy.top/t/topic/mAUe 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录