作者:自由飘落de花瓣 | 来源:互联网 | 2023-09-23 12:22
js倒计时如火车站买火车票后15分钟必须付款否则取消火车票
假设购买火车票下单的时间是dateTime(date 类型),然后倒计时15分钟
$(function(){
timer();
});
function timer(){
interval = setInterval("timer1()",1000);
}
function timer1(){
var leftTime = new Date().getTime() - dateTime.getTime();
leftTime = 15*60*1000 - leftTime;
var minute =parseInt(leftTime/1000/60%60,10);
var secOnd= parseInt(leftTime/1000%60,10);
var min = checkTime(minute);
var sec = checkTime(second);
$("#leftTimeTag").html(min + ":" + sec);
if(leftTime <1000){
alert("hello 倒计时结束");
clearInterval(interval);
}
}
function checkTime(i){
if(i <10 ){
i = "0" + i;
}
return i;
}