index.php
<script type="text/javascript">
$( document ).ready(function() {
$('[data-countdown]').each(function() {
var $this = $(this), finalDate = $(this).data('countdown');
$this.countdown(finalDate, function(event) {
$this.html('Time Left : '+ event.strftime('%D days %H:%M:%S'))}).on('finish.countdown', function() {
$this.html('This campaignn has expired!');
});
});
});
</script>
这是用于显示倒计时计时器的javascript。我使用的是jquery.dcounters.min.js插件。
<div class="counter-inner"> <div id="example<?php echo $rec['cid'];?>" data-countdown="<?php echo date("m/d/Y h:i:s", strtotime($rec['Closing_Date']));?>"></div></div><p>
Closing_Date和cid来自数据库。当我访问时,它运行良好。
但是,当我通过ajax将数据插入到index.php时,它不会起任何作用。javascript代码似乎没有被执行。
我检查了firebug,发现index.php文件中有日期,但它并没有显示倒计时计时器。
请告知
Ajax
$(document).ready(function() {
$('#more').click(function() {
var get_last_post_display = $('.unique-class:last').attr('id');
$('#more').html('<img src="ajax-loader.gif"');
$.post('more_prj.php', 'last_id_post='+get_last_post_display, function(html) {
if(html) {
$('#main-div').append(html);
$('#more').text('Load More Post'); //add text "Load More Post" to button again
} else {
$('#more').text('No more Post to load'); // when last record add text "No more posts to load" to button.
}
}, 'json');
});
});
将$('[data倒计时]').each(function)移动到ajax js,如下所示:
$(document).ready(function() {
$('#more').click(function() {
var get_last_post_display = $('.unique-class:last').attr('id');
$('#more').html('<img src="ajax-loader.gif"');
$.post('more_prj.php', 'last_id_post='+get_last_post_display, function(html) {
if(html) {
$('#main-div').append(html);
$('#more').text('Load More Post'); //add text "Load More Post" to button again
$('[data-countdown]').each(function() {
var $this = $(this), finalDate = $(this).data('countdown');
$this.countdown(finalDate, function(event) {
$this.html('Time Left : '+ event.strftime('%D days %H:%M:%S'))}).on('finish.countdown', function() {
$this.html('This campaignn has expired!');
});
});
} else {
$('#more').text('No more Post to load'); // when last record add text "No more posts to load" to button.
}
}, 'json');
});
});