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>

html() 関数で show() 関数を使用するにはどうすればよいですか、それとも別の方法がありますか?

手伝っていただけませんか?ありがとう。

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 に答える