테스트 사이트 - 개발 중인 베타 버전입니다

"답글보기" 누르면 답글 보이게 하는 법 채택완료

하호헤하 1년 전 조회 4,888

유튜브 댓글처럼 처음에는 답글을 숨겨놓고 답글 부분을 눌러야 답글이 나오게 하려고 합니다.

 

http://sir.kr/data/editor/2407/3034923468_1720633476.5157.jpg" width="100%" />

 

그래서 답글에

 

.comment_inner.comment_reply_folding 클래스를 지정해줬고 다음과 같이 코드를 작성했습니다.

 

<button class="btn_reply_view" data-comment-id="<?php echo $comment_id ?>">답글보기</button>

 

<script></p>

<p>$(document).ready(function() {</p>

<p>$('.comment_inner.comment_reply_folding').hide();</p>

<p> </p>

<p>$('.btn_reply_view').click(function() {</p>

<p>var comment_id = $(this).data('comment-id');</p>

<p>$('#' + comment_id + ' .comment_inner.comment_reply_folding').show();</p>

<p> });</p>

<p>});</p>

<p></script>

 

.comment_inner.comment_reply_folding{display:none} 해보니까 답글 사라지는 건 잘 돼서 답글에 클래스 적용은 잘 됐습니다.

 

그런데 답글보기 버튼을 눌러도 답글이 나타나지 않습니다.

 

$('.btn_reply_view').click(function() {</p>

<p>var comment_id = $(this).data('comment-id');</p>

<p>$('#' + comment_id + ' .comment_inner.comment_reply_folding').show();</p>

<p> });

 

위 코드를

 

$('.btn_reply_view').click(function() {</p>

<p>$('.comment_inner.comment_reply_folding').show();</p>

<p> });

 

위 코드로 바꾸니까 답글보기 버튼 눌렀을 때 모든 댓글의 모든 답글이 나타나는 게 가능합니다.

 

특정 댓글의 답글들을 지정하는 부분이 잘못된 거 같은데

 

어떻게 수정해야 답글보기를 누르면 해당 댓글의 답글만 보이게 될까요?

 

제가 봤을 땐 아래 부분을 수정해야 될 거 같은데 어떻게 수정해야 될지를 모르겠네요 ㅠㅠ

 

var comment_id = $(this).data('comment-id');</p>

<p>$('#' + comment_id + ' .comment_inner.comment_reply_folding').show();

 

(답글은 1단계만 사용하고 있습니다.)

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
1년 전

코드를 아래 처럼 변경 해주세요

 

움짤로 잘 되는거 확인해보세요

 

</p>

<p>    <?php</p>

<p>    $class ="";</p>

<p>    if(strlen($list[$i]['wr_comment_reply']) > 0){</p>

<p>        $class = "comment_inner comment_reply_folding";</p>

<p>    }else{</p>

<p>        $class = "no_reply";</p>

<p>    }</p>

<p>    ?></p>

<p> </p>

<p>    <article class="<?php echo $class ?>" id="c_<?php echo $comment_id ?>" <?php if ($cmt_depth) { ?>style="margin-left:<?php echo $cmt_depth ?>px;border-top-color:#e0e0e0"<?php } ?>></p>

<p> </p>

<p>

 

</p>

<p>$('.btn_reply_view').click(function() {</p>

<p>    if($(this).parents(".no_reply").length > 0){</p>

<p>        $(this).parents(".no_reply").next(".comment_inner.comment_reply_folding").show();</p>

<p>    }</p>

<p>});</p>

<p>

 

http://sir.kr/data/editor/2407/978180634_1720657645.0818.gif" width="100%" />

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

하호헤하
1년 전
감사합니다 미니님님

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인