我有腳本insertAfter超過一個格
.on('finish.countdown', function(event) {
$(this).text("<?php echo TEXT_SHIPPING_BARELY_PAST_DISPATCH; ?>").parent().addClass('disabled');
}) .insertAfter('#cartDefaultHeading');
的以下部分我想相同的輸出到後跨越幾個不同的頁面的多個格出現。如果我更改div名稱,它會按預期顯示在新位置。 但是,如果我試圖讓它出現在多個我沒有得到任何輸出。
我嘗試以下
.on('finish.countdown', function(event) {
$(this).text("<?php echo TEXT_SHIPPING_BARELY_PAST_DISPATCH; ?>").parent().addClass('disabled');
}) .insertAfter('#cartDefaultHeading').insertAfter('#checkoutOrderHeading');
和
.on('finish.countdown', function(event) {
$(this).text("<?php echo TEXT_SHIPPING_BARELY_PAST_DISPATCH; ?>").parent().addClass('disabled');
}) .insertAfter('#cartDefaultHeading'), .insertAfter('#checkoutOrderHeading') ;
甚至
.on('finish.countdown', function(event) {
$(this).text("<?php echo TEXT_SHIPPING_BARELY_PAST_DISPATCH; ?>").parent().addClass('disabled');
}) .insertAfter('#cartDefaultHeading');
$(this).text("<?php echo TEXT_SHIPPING_BARELY_PAST_DISPATCH; ?>").parent().addClass('disabled');
}) .insertAfter('#checkoutOrderHeading');
無工作。每當我嘗試在多個div上獲得它時,我都無法獲得它。 實現此目標的正確語法是什麼?
完整腳本如下所示:
<script>
jQuery(function($){
if (($('#cartDefaultHeading').length || $('#checkoutOrderHeading').length) && !$('.checkout_dispatch_timer').length) {
var $this = $('<div class="checkout_dispatch_timer <?php echo $dispatch_countdown_timer_style; ?>"></div>');
<?php if ($dispatch_countdown_timer_disable === false) { ?>
var finalDate = moment.tz('<?php echo $dispatch_countdown_timer_date_array[4]; ?>', '<?php echo date_default_timezone_get(); ?>');
$this.countdown(finalDate.toDate())
.on('update.countdown', function(event) {
var format = '%Mm';
if (event.offset.totalDays > 0) {
format = '%Dd:%Hh:' + format;
} else if (event.offset.totalHours > 0) {
format = '%Hh:' + format;
} else {
format = format + ':%Ss';
}
dispatch_countdown_timer_text = "<?php echo $dispatch_countdown_timer_text; ?>";
dispatch_countdown_timer_text = dispatch_countdown_timer_text.replace('%s', event.strftime(format));
$(this).text(dispatch_countdown_timer_text);
})
.on('finish.countdown', function(event) {
$(this).text("<?php echo TEXT_SHIPPING_BARELY_PAST_DISPATCH; ?>").parent().addClass('disabled');
})
.insertAfter('#cartDefaultHeading');
<?php } else { ?>
$this.text("<?php echo $dispatch_countdown_timer_text; ?>").insertAfter('#checkoutOrderHeading');
<?php } ?>
}
});
</script>
你想插入什麼?被插入的元素是'.on()'之前的元素,而不是您正在回顯的文本。 – Barmar
@Barmar它將根據數據庫中設置的值插入由moment.js計算出的時間。它還根據剩餘的瓦片數量構建特定的消息。 var $ dispatch_countdown_timer_text中的消息內容 –
寫入它的方式,insertAfter在加載頁面時發生,而不是在事件發生時發生。那是你要的嗎? – Barmar