您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

基于jQuery的倒计时插件代码_jquery

2025/3/19 13:38:53发布16次查看
剩余时间:1小时:40分:30秒
复制代码 代码如下:
1 /*
* 倒计时插件,主要用来限时购买
* by wayshan 版本1.0
* 使用方法:
* $(function(){
* $(#elementid).countdown({
* edate:2012-12-21 15:14:23
* });
* })
*/
;(function($){
$.fn.countdown = function(options){
if (this.length == 0){
return false;
}
return this.each(function(){
var default = {
sdate:null,//开始时间(格式为“2010-10-10 10:10:10”)可以设置为服务端的时间
edate:null,//结束日期(格式为“2010-10-10 10:10:10”)
callback:function(){
return false;
}
},
_h_text='小时',
_m_text='分',
_s_text='秒',
_lt = null,
_ct = new date(),
_et = null,
_elt = null,
ctime = null,
etime = null,
domid = null,
_timeout = null,
_gt = function(){
if (_lt == null) {
_elt = (etime - ctime);
if (_elt $('#'+domid).html(0+_h_text+:0+
_m_text+:0+_s_text);
}
var _xt =math.ceil(_elt/(24*60*60*1000));
_ct = parseint(_ct.match(/\s(\d+)\d/)[1] * 3600)
+ parseint(_ct.split(:)[1] * 60)+ parseint(_ct.split(:)[2]);
_et = _xt * 24 * 3600 + parseint(_et.match(/\s(\d+)\d/)[1] * 3600)
+ parseint(_et.split(:)[1] * 60) + parseint(_et.split(:)[2]);
_lt = _elt/1000;
}
if (_elt > 0) {
if (_lt >= 0) {
var _h = math.floor(_lt / 3600);
var _m = math.floor((_lt - _h * 3600) / 60);
var _s = (_lt - _h * 3600) % 60;
$('#'+domid).html( + _h + +_h_text+:
+ _m + +_m_text+: + _s + +_s_text);
_lt--;
} else {
clearinterval(_timeout);
if(s.callback && $.isfunction(s.callback)){
s.callback.call(this);
}
}
} else {
clearinterval(_timeout);
if(s.callback && $.isfunction(s.callback)){
s.callback.call(this);
}
}
},
strdatetime = function(str){
//判断日期时间的输入是否正确,类型必须形如为:2011-01-01 01:01:01
var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/;
var r = str.match(reg);
if(r==null)return false;
var d= new date(r[1], r[3]-1,r[4],r[5],r[6],r[7]);
return (d.getfullyear()==r[1]&&(d.getmonth()+1)==r[3]&&d.getdate()==r[4]
&&d.gethours()==r[5]&&d.getminutes()==r[6]&&d.getseconds()==r[7]);
}
var s = $.extend({}, default, options || {});
domid = this.id;
if (domid == 'null'){
return;
}
_et = s.edate;
if (!strdatetime(_et)){
alert('结束日期格式不正确');
return false;
}
if (s.sdate != null){
_ct = s.sdate;
}
_ct = _ct.tostring();
cdate = _ct.replace(/-/g, '/');
_et = _et.tostring();
edate = _et.replace(/-/g, '/');
ctime = new date(cdate);
etime = new date(edate);
_timeout = setinterval(_gt, 1000)
});
}
})(jquery);
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product