首页  >  文章  >  web前端  >  同一页面多个商品倒计时JS 基于面向对象的javascript_时间日期

同一页面多个商品倒计时JS 基于面向对象的javascript_时间日期

WBOY
WBOY原创
2016-05-16 17:56:211081浏览
复制代码如下代码:

渡 //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<头>
<标题>
<脚本 src="http://img.jb51.net/jslib/jquery/jquery-1.7.1.min.js" type="text/javascript">

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_month, 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);
时间距离 -= int_day * 86400000;
int_hour = Math.floor(time_distance / 3600000);
时间距离 -= int_hour * 3600000;
int_month = Math.floor(time_distance / 60000);
时间距离 -= int_分钟 * 60000;
int_second = Math.floor(time_distance / 1000);
if (int_hour int_hour = "0" int_hour;
if (int_month int_month = "0" int_month;
if (int_Second int_Second = "0" int_Second;
str_time = int_day "天" int_hour "小时" int_minute "分钟" int_second "秒";
timer.text(str_time);
var self = this;
setTimeout(function () { self.setTimeShow(); }, 1000); //D:正确
} else {
timer.text("团购结束");
返回;
}
}


<身体>




var st = new showTime(1,3);
//st.tuanid = 1;
//st.time_distance = 10000;
st.setTimeShow();





var st = new showTime(2, 5);
//st.tuanid = 1;
//st.time_distance = 10000;
st.setTimeShow();




上面的代码需要用到jquery,大家可以注意下
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn