我是新人,我一直在玩http://www.webcodo.net/comments-system-using-php-ajax/ 我添加了一些分页功能,但不知何故JS在那之后不起作用
的index.php
<?php
$page = (int)(!isset($_GET["page"]) ? 1 : $_GET["page"]);
if ($page <= 0) $page = 1;
$per_page = 3; // Set how many records do you want to display per page.
$startpoint = ($page * $per_page) - $per_page;
$statement = "`comments` ORDER BY `id` DESC";
$results = mysqli_query($db_conn,"SELECT * FROM {$statement} LIMIT {$startpoint} , {$per_page}");
if (mysqli_num_rows($results) != 0) {
// displaying records.
while ($row = mysqli_fetch_array($results)) {
?>
<div class="cmt-cnt">
<div class="thecom">
<h5><?php echo $row['name']; ?></h5><span data-utime="1371248446" class="com-dt"><?php echo $row['date']; ?></span>
<br/>
<p>
<?php echo $row['comment']; ?>
</p>
</div>
</div><!-- end "cmt-cnt" -->
<?php } } ?>
<div class="new-com-bt">
<span>Write a comment ...</span>
</div>
<div class="new-com-cnt">
<input type="text" id="name-com" name="name-com" value="" placeholder="Your name" />
<input type="text" id="mail-com" name="mail-com" value="" placeholder="Your e-mail adress" />
<textarea class="the-new-com"></textarea>
<div class="bt-add-com">Post comment</div>
<div class="bt-cancel-com">Cancel</div>
</div>
<div class="clear"></div>
<!-- echo $row['name'] . '<br>'; -->
</div><!-- end of comments container "cmt-container" -->
<?php // displaying paginaiton.
echo pagination($statement,$per_page,$page,$url='?');
// var_dump($pagination);
?>
</body>
<!-- JS script -->
<?php include_once('script.js'); ?>
</html>
这是javascript代码:
<script type = "text/javascript">
$(function(){
//alert(event.timeStamp);
$('.new-com-bt').click(function(event){
$(this).hide();
$('.new-com-cnt').show();
$('#name-com').focus();
});
/* when start writing the comment activate the "add" button */
$('.the-new-com').bind('input propertychange', function() {
$(".bt-add-com").css({opacity:0.6});
var checklength = $(this).val().length;
if(checklength){ $(".bt-add-com").css({opacity:1}); }
});
/* on clic on the cancel button */
$('.bt-cancel-com').click(function(){
$('.the-new-com').val('');
$('.new-com-cnt').fadeOut('fast', function(){
$('.new-com-bt').fadeIn('fast');
});
});
// on post comment click
$('.bt-add-com').click(function(){
var theCom = $('.the-new-com');
var theName = $('#name-com');
var theMail = $('#mail-com');
if( !theCom.val()){
alert('You need to write a comment!');
}else{
$.ajax({
type: "POST",
url: "ajax/add-comment.php",
data: 'act=add-com&id_post=+<?php echo $id_post; ?>+&name='+theName.val()+'&email='+theMail.val()+'&comment='+theCom.val(),
success: function(html){
theCom.val('');
theMail.val('');
theName.val('');
$('.new-com-cnt').hide('fast', function(){
$('.new-com-bt').show('fast');
$('.new-com-bt').before(html);
})
}
});
}
});
});
</script>