2

谢谢阅读。

我有评论列表,每条评论都有一个回复链接。当您单击链接时,应显示该个人评论的表单。

我很混乱。我写了这个 jquery,但我知道它甚至没有意义。

  <script>
     $('.reply-comment').click(function(){

    var CommentID = $(this).attr('id');

    $(this).hide();
    $('.reply-comment-form').show( function(){
        $('.reply-comment-form-'+CommentID).html();
    });

    return false;
});
</script>

这是表格

    <div class="reply-comment-form well">';
     <form name="reply-form" id="reply-form" method="POST">
      <textarea name="Comment" rows="6" class="span10"></textarea> <br />
      <input type="submit" class="btn btn-primary replycommentsubmitbutton" value="Yanitla" />
     </form>
    </div> 

我在每个评论下添加了一个跨度以显示表单

<div>
      comments text etc etc...
</div>
   <a href="" class="reply-comment" id="<?php $v['CommentID'] ?>"> Reply </a>
   <span id="reply-fomment-form-<?php $v['CommentsID'] ?>"></span>

那么,如何将 show() 函数与 html() 函数一起使用,或者还有其他方法吗?

请你帮助我好吗?谢谢。

4

2 回答 2

4

生成所有表单并隐藏这些表单,例如

HTML:

<div>comments text etc etc...</div>
<a href="" class="reply-comment" id="<?php $v['CommentID'] ?>"> Reply </a>
<form class="reply-form">
    <input />
    <input type="submit" />
</form>
<br />
<div>comments text etc etc...</div>
<a href="" class="reply-comment" id="<?php $v['CommentID'] ?>"> Reply </a>
<form class="reply-form">
    <input />
    <input type="submit" />
</form>

CSS:

.reply-form{ display:none; }

JS:

$(function(){
    $('.reply-comment').on('click', function(e){
        e.preventDefault();
        $(this).next('.reply-form').show();
    });
});

演示。 使用 OP 的标记更新了演示。

于 2013-09-19T20:37:08.117 回答
1

使用相对选择器并忘记整个 ID 事物。

$('.reply-comment').click(function(){
   $(this).next('.reply-comment-form').show()
})
于 2013-09-19T20:29:19.937 回答