目前前端代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="../js/jquery-3.4.1.min.js"></script>
<style>
html,
body,
.layuimini-container,
.layui-tab {
width: 100%;
height: 100%;
}
.layui-tab-content {
height: calc(100% - 61px);
}
.layui-tab-content .layui-tab-item {
height: 100%;
width: 100%;
}
.layui-side,
.layuimini-main {
position: relative;
}
.layui-tab-title li {
font-weight: bold;
padding: 0 20px;
}
</style>
</head>
<body>
<div class="layuimini-container">
<div class="newimg" id="newimg"></div>
</div>
<script src="../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
myfunction();
function myfunction() {
for (var i = 0; i < 2; i++) {
var mokuai = "<div class='img'>";
mokuai += "<div>";
mokuai += "<a href='javascript;'>";
mokuai += "<img src='../image/qrcode-corner.png' />";
mokuai += "</a>";
mokuai += "</div>";
mokuai += "<div class='text'>";
mokuai += "<span class='spana'>5人成团</span><span class='span'> </span><p class='jia'><span class='xianjia'>¥5.55</span><span style='color:#FF7013;'> </span><span style='color:#C9C9C9;' class='hua'>¥6.22</span></p>";
mokuai += "<p class='xs'><span>已成5团 / 可成10团 / 每人限购1份</span><span class='txt'>提货点:sdfgsd</span></p>";
mokuai += "<p class='djs'><span class='sp'>结束时间:</span><span id='sj1' class='sj"+i+"'></span></p>";
mokuai += ' <input type="hidden" class="time'+i+'" value="2022-03-2'+i+' 00:00:00" /> ';
mokuai += " </div>";
mokuai += "</div>";
mokuai += "<div>";
mokuai += "</br>";
var showtime = function () {
var nowtime = new Date(), //获取当前时间
endtime = new Date($(".time1").val()); //定义结束时间
var lefttime = endtime.getTime() - nowtime.getTime(), //距离结束时间的毫秒数
leftd = Math.floor(lefttime / (1000 * 60 * 60 * 24)), //计算天数
lefth = Math.floor(lefttime / (1000 * 60 * 60) % 24), //计算小时数
leftm = Math.floor(lefttime / (1000 * 60) % 60), //计算分钟数
lefts = Math.floor(lefttime / 1000 % 60); //计算秒数
return leftd + "天" + lefth + ":" + leftm + ":" + lefts; //返回倒计时的字符串
}
setInterval(function () {
var s = showtime();
$('.sj1').append(s);
$('.sj1').html(" ");
s = showtime();
$('.sj1').append(s);
}, 1000); //反复执行函数本身
$("#newimg").append(mokuai);
}
}
</script>
</body>
</html>