基于javascript实现的购物商城商品倒计时实例

来源:http://www.prospettivedarte.com 作者:计算机教程 人气:176 发布时间:2019-08-23
摘要:话不多说,下面跟着小编一起来看下实例代码吧 本文实例为大家分享了js倒计时代码,供大家参考,具体内容如下 Js: htmlheadtitle倒计时测试/title script src="http://www.prospettivedarte.com/upload

话不多说,下面跟着小编一起来看下实例代码吧

本文实例为大家分享了js倒计时代码,供大家参考,具体内容如下

Js:

<html>
<head>
<title>倒计时测试</title>
 <script src="http://www.prospettivedarte.com/uploads/allimg/190823/1445233c6-0.jpg" type="text/javascript"></script>
 <script language="JavaScript">

 $(document).ready(function () {
<!-- 时间必须启动 -->
 clockon();
 });


function clockon() {
 var now = new Date();
 var year = now.getFullYear(); //getFullYear getYear
 var month = now.getMonth();
 var date = now.getDate();
 var day = now.getDay();
 var hour = now.getHours();
 var minu = now.getMinutes();
 var sec = now.getSeconds();
 var week;
 month = month   1;
 if (month < 10) month = "0"   month;
 if (date < 10) date = "0"   date;
 if (hour < 10) hour = "0"   hour;
 if (minu < 10) minu = "0"   minu;
 if (sec < 10) sec = "0"   sec;
 var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");
 week = arr_week[day];
 var time = "";
 time = year   "年"   month   "月"   date   "日"   " "   hour   ":"   minu   ":"   sec   " "   week;
 $("#bgclock").html(time);



 var timer = setTimeout("clockon()", 200);
}


<!-- 隐藏脚本从旧的浏览器
var DifferHour = -1
var DifferMinute = -1
var DifferSecond = -1
var Tday1 = new Date("Feb 11, 2013 00:00:00") //**倒计时时间-注意格式
var daysms = 24 * 60 * 60 * 1000
var hoursms = 60 * 60 * 1000
var Secondms = 60 * 1000
var microsecond = 1000
function clock()

{
 var time = new Date()
 var hour = time.getHours()
 var minute = time.getMinutes()
 var second = time.getSeconds()
 var timevalue = "" ((hour > 12) ? hour-12:hour)
 timevalue  =((minute < 10) ? ":0":":") minute
 timevalue  =((second < 10) ? ":0":":") second
 timevalue  =((hour >12 ) ? " PM":" AM")
 var convertHour = DifferHour
 var convertMinute = DifferMinute
 var convertSecond = DifferSecond
 var Diffms = Tday1.getTime() - time.getTime()
 DifferHour = Math.floor(Diffms / daysms)
 Diffms -= DifferHour * daysms
 DifferMinute = Math.floor(Diffms / hoursms)
 Diffms -= DifferMinute * hoursms
 DifferSecond = Math.floor(Diffms / Secondms)
 Diffms -= DifferSecond * Secondms
 var dSecs = Math.floor(Diffms / microsecond)
 if(convertHour != DifferHour) document.formnow.dd.value=DifferHour
 if(convertMinute != DifferMinute) document.formnow.hh.value=DifferMinute
 if(convertSecond != DifferSecond) document.formnow.mm.value=DifferSecond
 document.formnow.ss.value=dSecs
 document.formnow.ss.value=dSecs
// document.formnow.Tnow.value= DifferHour DifferMinute   DifferSecond   dSecs

setTimeout("clock()",1000)



}

//



隐藏-->

</script>
</head>
<body onload="clock();return true" >
<!--显示出内容-->
<form name="formnow">
<input name="dd" type="text" style="border:0;" size=2>
天
<input name="hh" type="text" style="border:0;" size=2>
小时
<input name="mm" type="text" style="border:0;" size=2>
分
<input name="ss" type="text" style="border:0;" size=2>
秒

</form>

<!--倒计时完毕啦-->

</body>
</html> 
/**
 * Author: Black_Jay郗
 * downCount: 时间转换 倒计时
 */
(function ($) {
  $.fn.downCount = function (options, callback) {
    var settings = $.extend({
        date: null,
        offset: null
      }, options);
    if (!settings.date) {
      $.error('Date is not defined.');
    }
    if (!Date.parse(settings.date)) {
      $.error('Incorrect date format, it should look like this, 12/24/2012 12:00:00.');
    }
    var container = this;
    var currentDate = function () {
      var date = new Date();
      /*var utc = date.getTime()   (date.getTimezoneOffset() * 60000);
      var new_date = new Date(utc   (3600000*settings.offset));*/
      return date;
    };
    function countdown () {
      var target_date = new Date(settings.date),
        current_date = currentDate();
      var difference = target_date - current_date;
      if (difference < 0) {
        clearInterval(interval);//取消 setInterval() 函数设定的定时执行操作
        if (callback && typeof callback === 'function') callback();
        return;
      }
      var _second = 1000,
        _minute = _second * 60,
        _hour = _minute * 60,
        _day = _hour * 24;
      var days = Math.floor(difference / _day),
        hours = Math.floor(((difference % _day) / _hour)   (days*24)),
        minutes = Math.floor((difference % _hour) / _minute),
        seconds = Math.floor((difference % _minute) / _second);
        days = (String(days).length >= 2) ? days : '0'   days;
        hours = (String(hours).length >= 2) ? hours : '0'   hours;
        minutes = (String(minutes).length >= 2) ? minutes : '0'   minutes;
        seconds = (String(seconds).length >= 2) ? seconds : '0'   seconds;
      container.find('.hours').text(hours);
      container.find('.minutes').text(minutes);
      container.find('.seconds').text(seconds);
    };
    var interval = setInterval(countdown, 1000);
  };
})(jQuery);

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

html:

您可能感兴趣的文章:

<!-- 倒计时显示Star -->
<p class="countdown">
  00:
  00:
  00
</p>
<!-- 倒计时End -->

本文由皇牌天下投注网发布于计算机教程,转载请注明出处:基于javascript实现的购物商城商品倒计时实例

关键词:

最火资讯