2012-02-27 72 views
1

爲什麼我的倒數計時器不工作。我正在使用基思森林插件。已經上傳倒計時jquery到根。 http://keith-wood.name/countdownRef.htmlJquery倒計時器未能加載

CODE:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Untitled Document</title> 

<script type="text/javascript" src="jquery.js"></script> 
<link rel="stylesheet" href="jquerycd/jquery.countdown.css" type="text/css" /> 
<script type="text/javascript" src="jquerycd/jquery.countdown.js"></script> 

    <style> 
    defaultCountdown({until: liftoffTime}); 
</style> 

</head> 

<body> 
     <script> 
      var newYear = new Date(); 
newYear = new Date(newYear.getFullYear() + 1, 1 - 1, 1); 
$('#defaultCountdown').countdown({until: newYear}); 

$('#removeCountdown').toggle(function() { 
     $(this).text('Re-attach'); 
     $('#defaultCountdown').countdown('destroy'); 
    }, 
    function() { 
     $(this).text('Remove'); 
     $('#defaultCountdown').countdown({until: newYear}); 
    } 
); 
<div id="defaultCountdown"></div> 
</script> 
</body> 
</html> 
+0

您是否收到任何javascript錯誤?檢查你的Chrome或Firefox的控制檯。 – DG3 2012-02-27 13:45:50

+0

@ DG3在firefox中沒有檢查錯誤 – Jacob 2012-02-27 13:57:22

+2

您的CSS不相關 - 這就是您放在那裏的JavaScript命令,另外,您已經在腳本標記中獲得了div。 – Archer 2012-02-27 13:59:51

回答

2

您需要包括調用你的插件JS文件jQuery的文件被調用後。

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> 
<script type="text/javascript" src="jquerycd/jquery.countdown.js"></script> 

這是假設插件JS文件存在。

+0

我也上傳了自己的圖書館,未能加載到上面 – Jacob 2012-02-27 13:39:08

+0

請更新您的問題HTML。檢查你沒有404s等 – 472084 2012-02-27 13:39:59

+0

更新,沒有404s – Jacob 2012-02-27 13:43:16

0

這僅僅是一個整理版本的代碼,完成一個document.ready塊($(function() { ... }

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
     <title>Untitled Document</title> 
     <script type="text/javascript" src="jquery.js"></script> 
     <script type="text/javascript" src="jquerycd/jquery.countdown.js"></script> 
     <link rel="stylesheet" href="jquerycd/jquery.countdown.css" type="text/css" /> 
     <script> 
      $(function() { 
       var newYear = new Date(); 
       newYear = new Date(newYear.getFullYear() + 1, 0, 1); 
       $('#defaultCountdown').countdown({ until: newYear }); 
       $('#removeCountdown').toggle(function() { 
        $(this).text('Re-attach'); 
        $('#defaultCountdown').countdown('destroy'); 
       }, 
       function() { 
        $(this).text('Remove'); 
        $('#defaultCountdown').countdown({ until: newYear }); 
       }); 
      }); 
     </script> 
    </head> 
    <body> 
     <div id="defaultCountdown"></div> 
     <div id="removeCountdown">Remove</div> 
    </body> 
</html> 

我還添加了倒計時並切換DIV到文檔的主體。

+0

謝謝你的工作,但是CSS正在處理它。我的CSS是在jquerycd/jquery.countdown.css。我如何鏈接CSS的倒計時時間? – Jacob 2012-02-27 14:28:02

+0

我不明白你在問什麼。 css鏈接位於頁面頭部,並指向jquery/jquery.countdown.css。該css文件是否真的存在? – Archer 2012-02-27 14:31:15

+0

是的,它確實存在。在其中,每個元素都以.countdown _... – Jacob 2012-02-27 14:40:13