【问题标题】:How to show a box for comment reply with id如何显示带有 id 的评论回复框
【发布时间】: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


    【解决方案1】:

    如果我理解正确,您的问题是您有多个回复文本区域,但只有一个有效。我喜欢从最简单的错误开始,我说那是因为您在回复表单中的 textarea 只有一个 id。

    HTML 将提取它看起来的第一个 id/name,如果它们共享相同的名称,则丢弃其余的,如果第一个为空,那么这就是发布的内容。

    所以在某些时候您需要迭代“replycom”名称/id 这只是一个示例:

     $replyNumber = 0;
    
    ...
    
    
    <textarea name="replycom$replyNumber" rows="2" id="replycom$replyNumber"></textarea>
    

    编辑 我只记得可以在 HTMl 中将变量定义为数组

    <textarea name="replycom[]" rows="2" id="replycom"></textarea>
    

    【讨论】:

    • 谢谢无用的 Intem,没有你,没有人可以帮助或指导我。 5天之久我试图解决它。但我无法理解您的解决方案。怎么做?先生,再给我点东西。
    • 先生,我的每个表单都带有自己的 id,还保存用户名和父 id 等,但不能只保存 textarea 的文本。
    • 是的,它有一个 id,但它的 id 相同,至少在 bdshowbiz.com/loginfinal/demo.php 上。我检查了萤火虫。
    • 先生,请立即查看(不工作)bdshowbiz.com/loginfinal/demo.php
    【解决方案2】:

    通过添加一个在其值上动态添加文本的 javasrcipt 解决了问题。感谢无用的实习生先生也在这里评论我。

    $(".replycom").bind("keyup", function() {
    $(".replycom").text($(this).val());
    });
    

    【讨论】:

      猜你喜欢
      • 2018-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-18
      • 2016-01-22
      • 1970-01-01
      • 2015-08-09
      相关资源
      最近更新 更多