<script>
function countdown(){
jQuery(document).ready(function($){
var countdown_html = $('.countdown').clone();
var countDownDate = new Date("Apr 23, 2017 19:37:25").getTime();
// Update the count down every 1 second
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = countDownDate - now;
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance/(1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24))/(1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60))/(1000 * 60));
var seconds = Math.floor((distance % (1000 * 60))/1000);
$('.num.days', countdown_html).text(days);
$('.num.hours', countdown_html).text(hours);
$('.num.minutes', countdown_html).text(minutes);
$('.num.seconds', countdown_html).text(seconds);
$('.countdown').countdown({until: <?php echo $date['to'] ?>, layout: countdown_html.html() });
});
}
var run = setInterval(countdown,1000);
</script>
このコードは1秒後に1回だけカウントダウン機能を実行します。私は単純なカウントダウンタイマーを実装しようとしていますが、もう互換性のないWordPressのプラグインを拡張しています。私はJavaScriptの初心者です。上記はすべて100%コピーです&ペーストですが、機能の自動呼び出し以外はすべて動作します。JavaScript setIntervallは一度だけ実行されます
と呼ばれます'LL今のところ、1000ミリ秒ごとに1回だけイベントを登録していますが、明らかにDOMReadyイベントは1回しかトリガされません。setInterval(countdown、1000)しかし、 '$(document.ready)'は – haim770
です。あなたは 'jQuery(document).ready'が何をしているのか理解していません。 – dfsq
@ haim770' ready'コールバックはページが準備が整いました。それは変だけど、問題じゃない。 – Bergi