data.forEach((i,index)=>{ i.operatedate=i.operatedate.substring(0,10) let iconHtml = ''; if(i.operatedate === '2023-05-24'){ iconHtml = '<i class="glyphicon glyphicon-star-empty"></i>'; } $(".bottombingo").append(` <div class="bingodiv" style="margin-bottom:10px;" onclick="verxxggfb_id('\${i.id}')"> <div style="font-size:14px;font-weight:bolder;white-space:nowrap;overflow:hidden;">\${i.title} \${iconHtml}</div> <div style="font-size:12px;color:#3e3e3e;">\${i.operatedate}</div> </div>`) if(index == data.length-1){ //内部内容总高度 var height1 = $(".bottombingo").height(); var height2 = $(".bottombingo").parents('.card-table').height(); if(height1>height2){ //超出原本高度去进行上下走马灯 // setInterval(timerxxts,3000); var timer; // 定时器变量 // 启动定时器 timer = setInterval(timerxxts, 3000); // 鼠标进入 .bottombingo 时清除定时器 $(".bottombingo").on("mouseenter", function() { clearInterval(timer); }); // 鼠标离开 .bottombingo 时重新启动定时器 $(".bottombingo").on("mouseleave", function() { timer = setInterval(timerxxts, 3000); }); } } })修改这段代码使i.operatedate等于近三天的日期后iconHtml才有值
时间: 2023-12-11 18:03:06 浏览: 216
可以将第5行的日期判断条件改为:
```
if (new Date(i.operatedate) >= new Date(new Date().getTime() - 3 * 24 * 60 * 60 * 1000)) {
iconHtml = '<i class="glyphicon glyphicon-star-empty"></i>';
}
```
这样就可以判断i.operatedate是否在三天内了。具体代码如下:
```
data.forEach((i, index) => {
i.operatedate = i.operatedate.substring(0, 10);
let iconHtml = '';
if (new Date(i.operatedate) >= new Date(new Date().getTime() - 3 * 24 * 60 * 60 * 1000)) {
iconHtml = '<i class="glyphicon glyphicon-star-empty"></i>';
}
$(".bottombingo").append(`
<div class="bingodiv" style="margin-bottom:10px;" onclick="verxxggfb_id('${i.id}')">
<div style="font-size:14px;font-weight:bolder;white-space:nowrap;overflow:hidden;">${i.title} ${iconHtml}</div>
<div style="font-size:12px;color:#3e3e3e;">${i.operatedate}</div>
</div>`)
if (index == data.length - 1) {
//内部内容总高度
var height1 = $(".bottombingo").height();
var height2 = $(".bottombingo").parents('.card-table').height();
if (height1 > height2) {
//超出原本高度去进行上下走马灯 // setInterval(timerxxts,3000);
var timer; // 定时器变量
// 启动定时器
timer = setInterval(timerxxts, 3000);
// 鼠标进入 .bottombingo 时清除定时器
$(".bottombingo").on("mouseenter", function() {
clearInterval(timer);
});
// 鼠标离开 .bottombingo 时重新启动定时器
$(".bottombingo").on("mouseleave", function() {
timer = setInterval(timerxxts, 3000);
});
}
}
});
```
阅读全文