im我的JQUERY有一些问题。如何在JQUERY中添加特定DIV中的数据JQUERY
基本上,我有这种Facebook风格的显示帖子。每个帖子有<input>
框,其中成员可以发表评论。当用户点击我的jQuery(AJAX)<enter>
时,将获取提交的评论并将其保存在我的数据库中。
评论应立即出现在发表评论的特定<DIV>
。
我的问题是,每当我在一个特定的POST我做了更新,以ALL我的帖子的评论提交评论。它只会在我刷新时消失。
这是我<div>
显示的TITLE和评论
<div id="content">
<?php
/* GET TITLE*/
$result = displayPosts();
while ($row = $result->fetch_assoc()) {
$rowId = $row['id'];
?>
/* ECHO TITLE*/
<b> <?php echo $row['title'] . "<br />"; ?> </b>
<?php
/* GET COMMENTS PER POSTS */
$comRes = getComments($rowId);
while ($comRow = $comRes->fetch_assoc()) {
?>
<!--COMMENT AREA-->
<div class="comments">
<!--DISPLAY COMMENTS-->
<small> <?php echo $comRow['comment'] . "<br />";?> </small>
</div>
<?php } /* end of second while loop */ ?>
<input type="text" post_id="<?php echo $row['id']; ?>" id="TextBox" name="input" value="" />
<?php } /* end of first while loop */ ?>
</div>
THIS IS MY JQUERY。每当用户在特定POST命中<enter>
应该对特定DIV /帖子显示注释只有
$(document).ready(function() {
$('input#TextBox').keyup(function (z) {
/* when this commentbox is entered*/
if(z.keyCode == 13) { /*keyCode 13 = enter*/
var post_id = $(this).attr('post_id'); /* get the post_id in the <input> box */
var comment = $(this).val(); /* get the value of the <input> */
$.post('../portal/comment.php', {post_id: post_id, comment: comment});
$('input#TextBox').val('');
$(this).parent('#content').children('.comments').append("<div>"+comment+"</div>");
}
});
});
这一行包含了我post_id
所以每当我打在我的输入框中输入,我的系统知道具体是什么post im即指..
<input type="text" post_id="<?php echo $row['id']; ?>" id="TextBox" name="input" value="" />
哦,伙计!这次真是万分感谢! – bobbyjones
不客气;) – rd3n