jQuery使kellishaver秒表插件倒计时而不是向上 [英] jQuery make kellishaver stopwatch plugin countdown instead of up
问题描述
我需要秒表/计时器才能倒计时.我正在尝试使用 Kellis Havers秒表jQuery插件,并将其更改为倒计时.
I need a stopwatch/timer to countdown. I'm trying to use Kellis Havers stopwatch jQuery plugin and change it to countdown.
但是无法弄清楚如何减去而不是增加秒数,而是尝试更改"second ++;".到秒-";但得到的结果是00:03:0-1.它在评论中说parseInt()无法正常工作,所以我认为秒写在01 02 03 04等内容中.
But can't figure out how to make it substract instead of add seconds, tried changing the 'second++;' to 'second--;' but got this result= 00:03:0-1. It says in the comments that parseInt() is not working, so i figure it something with the seconds is written in 01 02 03 04 etc.
但是我还不够了解如何使它倒计时.
But I am not yet good enough to understand how to get it to countdown.
function do_time() {
// parseInt() doesn't work here...
hour = parseFloat(h.text());
minute = parseFloat(m.text());
second = parseFloat(s.text());
second++;
if(second > 59) {
second = 0;
minute = minute + 1;
}
if(minute > 59) {
minute = 0;
hour = hour + 1;
}
h.html("0".substring(hour >= 10) + hour);
m.html("0".substring(minute >= 10) + minute);
s.html("0".substring(second >= 10) + second);
}
}
})(jQuery);
推荐答案
parseInt
将可以正常工作rel ="nofollow">包括10作为第二个参数.
parseInt
will work fine if you include 10 as a second argument.
更改为:
hour = parseInt(h.text(),10);
minute = parseInt(m.text(),10);
second = parseInt(s.text(),10);
second--;
if(second < 0) {
second = 59;
minute = minute - 1;
}
if(minute < 0) {
minute = 59;
hour = hour - 1;
}
h.html("0".substring(hour >= 10) + hour);
m.html("0".substring(minute >= 10) + minute);
s.html("0".substring(second >= 10) + second);
这篇关于jQuery使kellishaver秒表插件倒计时而不是向上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!