【发布时间】:2014-11-24 15:02:21
【问题描述】:
我的回复仅适用于最后/新评论。如果我回复其他人的评论,它只会在文本区域显示一个空格。
测试用例:如果我在 wall.php 页面的末尾替换回复表单,应用 css display:block 以始终显示它,单击父 ID 的回复按钮并在写入任何文本后提交,然后它可以工作但单击回复按钮无法打开到它自己的回复表单。
如果我在页面末尾替换每条评论,如何打开我的回复表单?
wall.php(当前情况:如上链接不保存旧cmets的任何textarea数据)
script type='text/javascript'>
$(function(){
$("a.reply").click(function() {
var id = $(this).attr("id");
$("#parent_id").attr("value", id);
});
});
</script>
<script>
$('a.reply').livequery("click",function() {
var ID = $(this).attr('id').replace('','');
$("#reply_here-"+ID).slideToggle('slow');
return false;
});
</script>
</head>
global $dbh;
$results = mysqli_query($dbh,"SELECT * FROM comments_lite WHERE qazi_id='$tutid' ORDER BY id DESC LIMIT 5") or die(mysqli_error($dbh));
//find the number of comments
list($commentNum) = mysqli_fetch_array(mysqli_query($dbh,"SELECT COUNT(*) FROM comments_lite WHERE qazi_id='$tutid'"));
echo'<div class="comments"><div id="updates"><div class="content"><comment>';
while($rows = mysqli_fetch_array($results))
{
$id = $rows['id'];
$qazi_id = $rows['qazi_id'];
$likes = $rows['likes'];
$username = $rows['username'];
$img = $rows['img'];
$description = $rows['description'];
$url = $rows['url'];
$parent_id = $rows['parent_id'];
$date = $rows['date'];
echo'<div class="comment">
<div class="cdomment_cheder">';
if ($url=="") {
echo'<p class="name">'.$username.' Says:</p>'; }
else echo'<p class="name"><a href="userinfo.php?user='.$url.'" title="'.$username.'">'.$username.'</a> Says:</p>';
echo'<span class="cdomment_time">'.$date.'</span><br/>
<div class="avatarcnt">
<img alt="" src="uploadprofile/'.$u_imgurl.'"/>
</div></div></div>
<div class="cdomment_text">';
if ($description=="") {echo '';}
else echo''.htmlentities($description).'<br>';
echo '</div>';
//reply
echo'<div class="reply_box"><a href="javascript: void(0)" class="reply" id="'.$id.'">Reply</a></div>';
//Likes
echo'<div></div>';
// Only Reply
$query = "SELECT * FROM comments_reply WHERE parent_id ='".$id."' ORDER BY id DESC";
$res = mysqli_query($dbh,$query);
while($row = mysqli_fetch_array($res)){
$id = $row['id'];
$qazi_id = $row['qazi_id'];
$likes = $row['likes'];
$username = $row['username'];
$img = $row['img'];
$description = $row['description'];
$url = $row['url'];
$parent_id = $row['parent_id'];
$date = $row['date'];
echo' <div class="rcontent"><replycomment><ul>
<div class="comment">
<div class="cdomment_cheder">';
if ($url=="") {
echo'<p class="name">'.$username.' Says:</p>'; }
else echo'<p class="name"><a href="userinfo.php?user='.$url.'" title="'.$username.'">'.$username.'</a> Says:</p>';
echo'<span class="cdomment_time">'.$date.'</span><br/>
<div class="avatarcnt">
<img alt="" src="uploadprofile/'.$u_imgurl.'"/>
</div></div></div>
<div class="cdomment_text">';
if ($description=="") {echo '';}
else echo''.htmlentities($description).'<br>';
echo '</div>';
</ul><replycomment></div>';
} //reply close
?>
// REPLY FORM
<div id="loader"></div><div class="reply_here" id="reply_here-<?php echo $rows['id'] ?>" style="display:none;">
<form action="" method="post" id="repfrm">
<fieldset id="cmntfs">
<legend class="pyct">Your comment</legend>
<input type="hidden" name="username" id="author" value="<?php echo $_SESSION['username'] ?>"/>
<input type="hidden" name="url" id="url" value="" />
<div id="maintbox">
<textarea name="replycom" rows="2" id="replycom"></textarea>
</div>
<input type="hidden" name="parent_id" id="parent_id" value="0" />
<input type="hidden" name="tutid" id="tutid" value="<?php echo $tutid ?>" />
<button type="submit" name="submit" value="" id="submit" class="repfrm">Post Reply</button>
</fieldset>
</form>
</div>
<?
} //comment close
echo'</div><comment></div>';
//pagination
wall.php(测试案例:当表单放在页面末尾时,这不会打开每个回复表单)
script type='text/javascript'>
$(function(){
$("a.reply").click(function() {
var id = $(this).attr("id");
$("#parent_id").attr("value", id);
});
});
</script>
<script>
$('a.reply').livequery("click",function() {
var ID = $(this).attr('id').replace('','');
$("#reply_here-"+ID).slideToggle('slow');
return false;
});
</script>
</head>
global $dbh;
$results = mysqli_query($dbh,"SELECT * FROM comments_lite WHERE qazi_id='$tutid' ORDER BY id DESC LIMIT 5") or die(mysqli_error($dbh));
//find the number of comments
list($commentNum) = mysqli_fetch_array(mysqli_query($dbh,"SELECT COUNT(*) FROM comments_lite WHERE qazi_id='$tutid'"));
echo'<div class="comments"><div id="updates"><div class="content"><comment>';
while($rows = mysqli_fetch_array($results)) {
$id = $rows['id'];
$qazi_id = $rows['qazi_id'];
$likes = $rows['likes'];
$username = $rows['username'];
$img = $rows['img'];
$description = $rows['description'];
$url = $rows['url'];
$parent_id = $rows['parent_id'];
$date = $rows['date'];
echo'<div class="comment">
<div class="cdomment_cheder">';
if ($url=="") {
echo'<p class="name">'.$username.' Says:</p>'; }
else echo'<p class="name"><a href="userinfo.php?user='.$url.'" title="'.$username.'">'.$username.'</a> Says:</p>';
echo'<span class="cdomment_time">'.$date.'</span><br/>
<div class="avatarcnt">
<img alt="" src="uploadprofile/'.$u_imgurl.'"/>
</div></div></div>
<div class="cdomment_text">';
if ($description=="") {echo '';}
else echo''.htmlentities($description).'<br>';
echo '</div>';
//reply
echo'<div class="reply_box"><a href="javascript: void(0)" class="reply" id="'.$id.'">Reply</a></div>';
//Likes
echo'<div></div>';
// Only Reply
$query = "SELECT * FROM comments_reply WHERE parent_id ='".$id."' ORDER BY id DESC";
$res = mysqli_query($dbh,$query);
while($row = mysqli_fetch_array($res)){
$id = $row['id'];
$qazi_id = $row['qazi_id'];
$likes = $row['likes'];
$username = $row['username'];
$img = $row['img'];
$description = $row['description'];
$url = $row['url'];
$parent_id = $row['parent_id'];
$date = $row['date'];
echo' <div class="rcontent"><replycomment><ul>
<div class="comment">
<div class="cdomment_cheder">';
if ($url=="") {
echo'<p class="name">'.$username.' Says:</p>'; }
else echo'<p class="name"><a href="userinfo.php?user='.$url.'" title="'.$username.'">'.$username.'</a> Says:</p>';
echo'<span class="cdomment_time">'.$date.'</span><br/>
<div class="avatarcnt">
<img alt="" src="uploadprofile/'.$u_imgurl.'"/>
</div></div></div>
<div class="cdomment_text">';
if ($description=="") {echo '';}
else echo''.htmlentities($description).'<br>';
echo '</div>';
</ul><replycomment></div>';
} //reply close
} //comment close
?>
// REPLY FORM
<div id="loader"></div><div class="reply_here" id="reply_here-<?php echo $rows['id'] ?>" style="display:block;">
<form action="" method="post" id="repfrm">
<fieldset id="cmntfs">
<legend class="pyct">Your comment</legend>
<input type="hidden" name="username" id="author" value="<?php echo $_SESSION['username'] ?>"/>
<input type="hidden" name="url" id="url" value="" />
<div id="maintbox">
<textarea name="replycom" rows="2" id="replycom"></textarea>
</div>
<input type="hidden" name="parent_id" id="parent_id" value="0" />
<input type="hidden" name="tutid" id="tutid" value="<?php echo $tutid ?>" />
<button type="submit" name="submit" value="" id="submit" class="repfrm">Post Reply</button>
</fieldset>
</form>
</div>
<?
echo'</div><comment></div>';
//pagination
【问题讨论】:
标签: javascript php jquery