javascript - Jquery 中的计时器

标签 javascript jquery jsp jquery-plugins timer

我在google上查了很多,没有找到可靠的。这就是我问这个问题的原因。

我正在动态创建一个 iframediv 中的 iframe。

我需要显示并启动TIMER计数,从[00:00:00]开始,其格式为[hh:mm: ss] ,在我的 JSP 完全加载后。

所以我使用了以下插件 http://tutorialzine.com/2012/09/count-up-jquery/

但它在 IE 中不起作用,但在 chromefirefox 中起作用。只有我收到了警报消息。除了什么也没发生之外。我的 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/

相关文章:

Javascript React Switch Case 带有动态键?

javascript - 如何通过Jquery将三个选择框排列成一个序列

改变元素在滚动条上位置的 jQuery 代码

jquery - 使用 jQuery 动态更改 AddThis url

java - jsp基于boolean true false隐藏列表项

javascript - 每 x 秒清除一次输入框

javascript - 我无法正确使用 setState 来更改值

javascript - React 无状态组件 clearTimeout 似乎不起作用

java - 在 JSP 页面上显示树

javascript - 如何在JSP中很好地拆分表格