为什么我的倒数计时器不起作用。我正在使用keith woods插件。已将倒计时jquery上传到root。 http://keith-wood.name/countdownRef.html
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 :(得分:2)
在调用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文件存在。
答案 1 :(得分: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添加到文档正文中。