我有jQuery問題,我使用下面的代碼來獲取日期格式json,這段代碼工作正常。倒計時jquery
在執行console.log(時代報)我可以看到這個日期
2015/11/21 12:34:56
ex.html:15 2016/10/10 12:34:56
ex.html:15 2017/10/10 12:34:56
ex.html:15 2018/10/10 12:34:56
ex.html:15 2019/10/10 12:34:56
然而,在HTML我只看到我從JSON收到的第一次約會。
<script type="text/javascript">
function tiempo(tiempo){
console.log(tiempo);
$('.clock').countdown(tiempo, function(event) {
$(this).html(event.strftime('%D days %H:%M:%S'));
});
}
</script>
<script type="text/javascript">
var arr = [
{"transporte":"Servei de Rodalies Barcelona","now":"2015/11/21 12:34:56"},
{"transporte":"Serveis Regionals","now":"2016/10/10 12:34:56"},
{"transporte":"Ferrocarrils","now":"2017/10/10 12:34:56"},
{"transporte":"Metro","now":"2018/10/10 12:34:56"},
{"transporte":"Tram","now":"2019/10/10 12:34:56"}
];
jQuery.each(arr, function(index, value) {
$(".prueba").append('<div class="clock"></div>');
tiempo(value.now);
});
</script>
圖像更好解釋。
UPDATE
Wihich這段代碼中,只顯示一個日期
<body>
<div class="clock"></div>
</body>
<script type="text/javascript">
function tiempo(tiempo){
$('.clock').countdown(tiempo, function(event) {
$(this).html(event.strftime('%D days %H:%M:%S'));
});
}
</script>
<script type="text/javascript">
var arr = [
{"transporte":"Servei de Rodalies Barcelona","now":"2015/11/21 12:34:56"},
{"transporte":"Serveis Regionals","now":"2016/10/10 12:34:56"},
{"transporte":"Ferrocarrils","now":"2017/10/10 12:34:56"},
{"transporte":"Metro","now":"2018/10/10 12:34:56"},
{"transporte":"Tram","now":"2019/10/10 12:34:56"}
];
for (var i = 0 ; i < arr.length ; ++i) {
tiempo(arr[i].now);
}
</script>
是什麼的_countdown_功能嗎?它是一個'jquery'插件嗎? –