列表中,時間的倒計時方法
阿新 • • 發佈:2019-01-04
<script type="text/javascript">
$(function(){
//每一行的操作
$("#contentTable tr td:nth-child(7)").each(function (key, value) {
var td = $(this);
var strTime = $(this).html();
if(strTime == '' || strTime == null || strTime == undefined)
;
else{
var date = strTime.split("天");
var hours = date[1].split("小時");
var minutes = hours[1].split("分");
var secends = minutes[1].split("秒");
/* alert(date[0]);
alert(hours[0]);
alert(minutes[0]);
alert(secends[0]); */
var totalSeconds = date[0] * 24 * 60 * 60 + hours[0] * 60 * 60 + minutes[0] * 60 + parseInt(secends[0]);
//alert(totalSeconds);
if(parseInt(totalSeconds) > 0){
var timerVal = totalSeconds;
var i = setInterval(function() {
timerVal--;
var day=Math.floor(timerVal/(24*60*60));
var hour=Math.floor(timerVal/(60*60)-day*24);
var min=Math.floor((timerVal/(60))-day*24*60-hour*60);
var s=Math.floor(timerVal-day*24*60*60-hour*60*60-min*60);
var leftTime = ""+day+"天"+hour+"小時"+min+"分"+s+"秒";
// alert(leftTime);
td.html(leftTime);
if (timerVal < 1)
clearInterval(i);
}, 1000);
}
}
});
});
function page(n,s){
$("#pageNo").val(n);
$("#pageSize").val(s);
$("#searchForm").submit();
return false;
}
</script>
$(function(){
//每一行的操作
$("#contentTable tr td:nth-child(7)").each(function (key, value) {
var td = $(this);
var strTime = $(this).html();
if(strTime == '' || strTime == null || strTime == undefined)
;
else{
var date = strTime.split("天");
var hours = date[1].split("小時");
var minutes = hours[1].split("分");
var secends = minutes[1].split("秒");
/* alert(date[0]);
alert(hours[0]);
alert(minutes[0]);
alert(secends[0]); */
var totalSeconds = date[0] * 24 * 60 * 60 + hours[0] * 60 * 60 + minutes[0] * 60 + parseInt(secends[0]);
//alert(totalSeconds);
if(parseInt(totalSeconds) > 0){
var timerVal = totalSeconds;
var i = setInterval(function() {
timerVal--;
var day=Math.floor(timerVal/(24*60*60));
var hour=Math.floor(timerVal/(60*60)-day*24);
var min=Math.floor((timerVal/(60))-day*24*60-hour*60);
var s=Math.floor(timerVal-day*24*60*60-hour*60*60-min*60);
var leftTime = ""+day+"天"+hour+"小時"+min+"分"+s+"秒";
// alert(leftTime);
td.html(leftTime);
if (timerVal < 1)
clearInterval(i);
}, 1000);
}
}
});
});
function page(n,s){
$("#pageNo").val(n);
$("#pageSize").val(s);
$("#searchForm").submit();
return false;
}
</script>