ajax 댓글 새로고침 클릭 문제 문의드립니다.
본문
nsnsksks님 팁으로 그누보드 5.4.2.2에 ajax 댓글 새로고침없이 달기를 적용했는데요.
https://sir.kr/g5_plugin/4972
댓글 등록은 잘됩니다.
문제는 <ajaxcomment></ajaxcomment> 부분만 리로드가 되어서
댓글열기와 댓글 옵션창 열기가 클릭이안됩니다.
즉 새로고침이 안되어서 클릭이 안됩니다.
페이지 전체 새로고침하면 클릭이 잘됩니다.
아래의 코드에서 어떻게 수정하면
<ajaxcomment></ajaxcomment>
이 부분을 새로고침 되어서 클릭이 되게 할수 없을까요?
고수님들 도움 좀 부탁 드립니다.
view_comment.skin.php 댓글부분<ajaxcomment>로 감싸기
<!-- 댓글 시작 { -->
<ajaxcomment>
<section id="bo_vc">
...
</section>
</ajaxcomment>
<!-- } 댓글 끝 -->
fviewcomment_submit 함수 추가
// ajax comment system
$.ajax({
url: f.action,
type: 'POST',
data: $(f).serialize(),
dataType: 'html',
})
.done(function(str) {
var tempDom = $('<output>').append($.parseHTML(str))
var title = $('title', tempDom).text()
if (title === '') {
// 1. commentBox 원위치
comment_box('', 'c')
// 2. commentBox Form 리셋
f.reset()
// 3. 코멘트 출력
$.ajax({
url: str,
type: 'GET',
dataType: 'html'
})
.done(function(str2) {
var tempDom2 = $('<output>').append($.parseHTML(str2))
$('ajaxcomment').replaceWith($('ajaxcomment', tempDom2))
})
}
댓글 옵션창 열기 코드
<script>
$(function() {
// 댓글 옵션창 열기
$(".btn_cm_opt").on("click", function(){
$(this).parent("div").children(".bo_vc_act").show();
});
// 댓글 옵션창 닫기
$(document).mouseup(function (e){
var container = $(".bo_vc_act");
if( container.has(e.target).length === 0)
container.hide();
});
});
</script>
댓글열기 코드
$(function() {
//댓글열기
$(".cmt_btn").click(function(){
$(this).toggleClass("cmt_btn_op");
$("#bo_vc").toggle();
});
});
</script>
<?php } ?>
답변 1
$(
".btn_cm_opt"
).on(
"click"
,
function
(){
->
$(document).on("click", ".btn_cm_opt", function(){
$(
".cmt_btn"
).click(
function
(){
->
$(document).on("click", ".cmt_btn", function(){
이런식으로 수정해보세요
동적 생성된 element들은 jquery 버전에 따라
bind, on, live 쓰는 방식들이 조금씩 다릅니다.
답변을 작성하시기 전에 로그인 해주세요.