일반적인 댓글 쓰기입니다.
IE브라우져에서는 글 입력 후 등록 버튼을 누르면 입력된 저장되면서 없어지는데,
나머지 크롬, 사파리, 모바일브라우져 등에서는 계속 남아있어서
계속 등록 버튼을 눌러 같은 글이 여러번 등록되는 케이스가 나와서..
왜 표준 브라우져에서는 초기화 되지 않을까요?
Copy
echo ' <div class="replywrite comment_write"> <form id="fcomment'.$i.'"> <input type="hidden" name="mode" value="signcomment"> <input type="hidden" name="wr_id" value="'.$pshow[wr_id].'"> <input type="hidden" name="showbox" value="show_comment_box'.$i.'"> <p>댓글쓰기</p> <textarea id="wr_content'.$i.'" name="wr_content" required class="required"></textarea>'; if($is_member) { echo '<button type="button" onclick="check_comment'.$i.'()">등록</button>'; } else { echo '<button type="button" onclick="alert(\'회원전용입니다. 로그인후 사용하세요.\');">등록</button>'; } echo '</form> '; echo ' <script> function check_comment'.$i.'() { if(!$("#wr_content'.$i.'").val()) { alert(\'댓글을 작성하신후 등록하세요.\'); return false; } ajax_form("fcomment'.$i.'"); } </script> </div> '; function ajax_form(formid) { $.ajax ({ type:"POST", url:"savedata.php", data:$('#'+formid).serialize(), success:function(html) { var htmls = html.split("[:]"); if(htmls[0] == "signcomment") { $('#'+htmls[1]).html(htmls[2]); $('.comment_write textarea').text(''); } else if(htmls[0] == "signreview") { $('#'+htmls[1]).html(htmls[2]); $('.comment_write textarea').text(''); } else if(htmls[0] == "warn") { alert(htmls[1]); } }, error: function(xhr, option, error){ alert(xhr.status); alert(error); } });}
답변 1개
채택된 답변
+20 포인트
10년 전
<form id="
이 부분에 $i가 붙는 건가요?
form이 한 개가 아니란 소리네요.
거기다가 호출하는 함수도 여러 갠 거 같구요.
실제 html 페이지가 어떻게 나오는지 모르겠지만
ajax_form("fcomment'.$i.'");
$("form").each(function() {
$(this)[0].reset();
});
이렇게 넣어 보세요.
답변을 작성하려면 로그인이 필요합니다.