jsオブジェクト適用の団体購入時間カウントダウン
1917 ワード
最近、shopex 485で友达を手伝って団体購入の機能を作っています.フロントの団体購入商品はカウントダウンしています.団体購入の商品は複数あるかもしれませんが、各商品の終了時間も必ずしも同じではありません.だから、それぞれの商品に対象を作る必要があります.一晩中振り回されて、やっと新鮮になった.jsオブジェクトでsettimeoutを使うのは少し学問的です.
<script type="text/javascript">
//
var service_time=<?php echo $now_time; ?>;
function showTime(tuanid,time_distance){
this.tuanid = tuanid;
//PHP ,JS
this.time_distance = time_distance*1000;
}
showTime.prototype.setTimeShow=function(){
var timer = $('lefttime_'+this.tuanid);
var str_time;
var int_day,int_hour,int_minute,int_second;
time_distance = this.time_distance;
this.time_distance = this.time_distance-1000;
if(time_distance>0){
int_day=Math.floor(time_distance/86400000);
time_distance-=int_day*86400000;
int_hour=Math.floor(time_distance/3600000);
time_distance-=int_hour*3600000;
int_minute=Math.floor(time_distance/60000);
time_distance-=int_minute*60000;
int_second=Math.floor(time_distance/1000);
if(int_hour<10)
int_hour="0"+int_hour;
if(int_minute<10)
int_minute="0"+int_minute;
if(int_second<10)
int_second="0"+int_second;
str_time=int_day+" "+int_hour+" "+int_minute+" "+int_second+" ";
timer.innerHTML = str_time;
var self=this;
setTimeout(function(){self.setTimeShow();},1000);//D:
}else{
timer.innerHTML =' ';
return;
}
}
</script>