【问题标题】:Countdown script not starting countdown倒计时脚本未开始倒计时
【发布时间】:2013-01-02 00:30:19
【问题描述】:

有人可以告诉我为什么倒计时功能无法正常工作(倒计时不是从带有 I.D.“倒计时”的 div 开始的)。可能真的很简单,但 Javascript 不是我的强项。这是我正在使用的倒计时插件:http://keith-wood.name/countdown.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Page Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="./css/web-style-second.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="chrome://mozbar/skin/css/injected.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.countdown.js"></script>
</head>
<body>
<a name="top"></a>
<div id="container">
    <div id="content">  

<div class="center">
    <center>
        <div></div>
    </center>
</div>

<script type="text/javascript"> 
$(function() {
    $('#countdown').countdown({
        until: '14min+20sec',
        format: 'MS',
        layout: '{mnn}min  ' + '{snn}sec  ',
        onExpiry: function() {
            $(".hidden").css("display", "block");
        }
    });
});
</script>

<div class="time_box"> 
    <h3 class="italic">When The Clock Hits Zero ... </h3> 
    <h4 class="hasCountdown" id="countdown">14min  20sec  </h4>  
</div>

<form name="signupFrm" id="signupFrm" action="#" method="post" class="hidden">
    <div>
        <div class="yellow_red">
            <h1></h1>
        </div>
        <div class="center">
            <a href="https://www.testing.com" class="btn_buy_now">
            Get Started</a>
        </div>
        <input name="submit" value="submit" type="hidden">
        <p class="mb_5">&nbsp;</p>
    </div>
</form>
<div class="fnote justify">
</div>


    </div>
    <div id="footer">
    </div>
</div>


</body>
</html>

【问题讨论】:

  • 您缺少“jQuery Countdown CSS”参考

标签: javascript jquery-plugins countdown


【解决方案1】:

您应该将$(function () ...) 脚本放入HTML 页面的&lt;head&gt; 标记中。这样,一旦 DOM 完全加载,就会开始倒计时。

【讨论】:

    【解决方案2】:

    我认为问题在于您缺少对“jQuery Countdown CSS”的引用。在usage instructions of the plugin 中它说:

    下载 jQuery Countdown CSS 和 JavaScript 并将其包含在 页面的 head 部分。 @进口 "jquery.countdown.css";

    但如果您从 ID 为“countdown”的&lt;h4&gt; 元素中删除class 属性,您仍然可以在没有“jQuery Countdown CSS”的情况下使其工作,如下所示:

    <div class="time_box"> 
        <h3 class="italic">When The Clock Hits Zero ... </h3> 
        <h4 id="countdown">14min  20sec  </h4>  
    </div>
    

    JSFiddle Example

    【讨论】:

      【解决方案3】:

      倒计时插件使用类hasCountdown来测试倒计时是否已经被实例化,所以你应该使用不同的类名。

      来自 jquery.countdown.js:

      /* Class name added to elements to indicate already configured with countdown.*/
      markerClassName: 'hasCountdown'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-05-05
        • 1970-01-01
        • 2015-10-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-27
        相关资源
        最近更新 更多