-1
我有和html計算了我的活動的日子,現在事件結束,計數器顯示的天數爲負數。我如何使現有的JS代碼計數。我對學習html和js相當陌生,並且非常感謝您的知識。Javascript - 更改countDown計時器countUp時間
下面是從外部鏈路JS文件的代碼:
/*-----Countdown timer created by webnesters.com-------*/
jQuery.fn.CountingDown = function(options) {
\t var settings = jQuery.extend({
\t \t 'date': null
\t },
\t options);
\t myp=jQuery(this);
\t function calculate_time(){
\t \t var future = Date.parse(settings[
\t \t \t 'date'
\t \t ]);
var now = new Date();
\t
var difference = Math.floor((future - now)/1000);
var seconds = chkinteger(difference % 60);
\t
difference = Math.floor(difference/60);
var minutes = chkinteger(difference % 60);
\t
difference = Math.floor(difference/60);
var hours = chkinteger(difference % 24);
\t
difference = Math.floor(difference/24);
var days = difference;
\t if(days.toString().length==1){
\t \t days='0'+days;
\t }
myp.find("#seconds").text(seconds);
myp.find("#minutes").text(minutes);
\t myp.find("#hours").text(hours);
\t myp.find("#days").text(days);
\t }
\t
\t function chkinteger(integer)
\t {
\t \t if (integer < 0)
integer = 0;
if (integer < 10)
return "0" + integer;
return "" + integer;
\t }
\t calculate_time();
\t interval = setInterval(calculate_time,1000);
};
下面是從HTML的代碼:
<h4>12 november 2016</h4>
<div class="countdown-container" id="countdown">
<div class="countdown-box-wrap-year">
<div class="countdown-box">
<div class="countdown-box-border-year">
</div>
<div class="countdown-box-border-year2">
</div>
<span id="days">00</span>
</div>
<strong>Days</strong>
</div>
<div class="countdown-box-wrap">
<div class="countdown-box">
<div class="countdown-box-border">
</div>
<span id="hours">00</span>
</div>
<strong>Hours</strong>
</div>
<div class="countdown-box-wrap">
<div class="countdown-box">
<div class="countdown-box-border">
</div>
<span id="minutes">00</span>
</div>
<strong>Minutes</strong>
</div>
<div class="countdown-box-wrap">
<div class="countdown-box">
<div class="countdown-box-border">
</div>
<span id="seconds">00</span>
</div>
<strong>Seconds</strong>
</div>
</div>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#countdown").CountingDown({
date: "12 november 2016 14:00:00" // Enter your countdown date and time
});
});
</script>
我會盡力回覆你。這是有道理的,基本的數學哈哈。傻我。 – user1905097