我在google上查了很多,没有找到可靠的。这就是我问这个问题的原因。
我正在动态创建一个 iframe
和 div
中的 iframe。
我需要显示并启动TIMER
计数,从[00:00:00]开始,其格式为[hh:mm: ss] ,在我的 JSP
完全加载后。
所以我使用了以下插件
http://tutorialzine.com/2012/09/count-up-jquery/
但它在 IE 中不起作用,但在 chrome 和 firefox 中起作用。只有我收到了警报消息。除了什么也没发生之外。我的 JSP 代码是,
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script src="js/jquery-1.9.1.js"></script>
<script src="js/assets/countup/jquery.countup.js"></script>
<script type="text/javascript">
$(function() {
alert("DOM loaded");
$('#countdown').countup();
});
</script>
</head>
<body>
<h2>Timer is :</h2>
<p id="countdown"></p>
</body>
</html>
我不知道为什么这对我不起作用。
我的需求:
我需要显示并启动
TIMER
计数,从[00:00:00]开始,格式为[hh :mm:ss] ,当 DOM 以指定格式在 IE 中完全加载后。或者建议我任何其他事情来使这个场景发挥作用。
希望我们的堆栈用户能够帮助我。
最佳答案
最后,我通过自己的代码找到了满足我需求的解决方案,
var hours = 0;
var minutes = 0;
var seconds = 0;
$(function() {
setInterval(counter, 1000);
});
function counter() {
var hh = 0;
var mm = 0;
var ss = 0;
seconds = seconds + 1;
ss = seconds + 1;
if (seconds == 60) {
seconds = 0;
minutes = minutes + 1;
mm = minutes + 1;
if (minutes == 60) {
minutes = 0;
hours = hours + 1;
hh = hours + 1;
}
}
if (seconds < 10) {
ss = "0" + seconds;
}else{
ss = seconds;
}
if (minutes < 10) {
mm = "0" + minutes;
}else{
mm = minutes;
}
if (hours < 10) {
hh = "0" + hours;
}else{
hh = hours;
}
$('#displayTime').html("[ " +hh + " : " + mm + " : " + ss+" ]");
}
关于javascript - Jquery 中的计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19028693/