为什么我的倒计时计时器不工作。我正在使用keith woods插件。已将倒计时jquery上传到root。http://keith-wood.name/countdownRef.html
代码:
<!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>
在调用jQuery文件后,您需要包含对插件JS文件的调用。
<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文件存在。
这只是代码的一个整理版本,包含一个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。