【发布时间】:2016-03-15 16:57:19
【问题描述】:
我正在尝试使用 jQuery 插件进行倒计时。 (我也使用 php 框架)。这是我在主页中的脚本:
<script type="text/javascript">
$(document).ready(function () {
$.get(baseUrl + "/countdown", {id: "609|610|611|612"}, function (data) {
auctions = data.split("||");
for (n = 0; n < auctions.length; n++) {
if (auctions[n] != undefined) {
divis = auctions[n].split("##");
if (divis[1] != "stop") {
$('#bid' + divis[0]).countdown(divis[1], function (event) {
var totalHours = event.offset.totalDays * 24 + event.offset.hours;
$(this).html(event.strftime(totalHours + ' hr %M min %S sec'));
});
} else {
$('#bid' + divis[0]).html("closed");
}
}
}
});
});
“倒计时”是一个返回此字符串的 php 文件:
609##stop||610##stop||611##2016/03/28 13:00:56||612##2016/04/03 01:00:00||
使用它会导致我出现太多错误。如果我将“auctions.length”更改为“4”,一切都会变得正常!我检查了“data”的值,而不是“countdown.php”返回的确切字符串,它更大并且包含一些空格!我还检查了“auctions.length”的值,它是 7! 我不知道为什么会这样。
当我将 $.get 更改为 $.getJSON 时,也不会显示倒计时。这是为什么呢?
感谢您的关注:) 感谢您对我的英语错误的宽容。
【问题讨论】:
标签: javascript jquery get getjson countdown