[해결]jsp javascript 질문 좀 드립니다.
글쓴이: lalupo20 / 작성시간: 토, 2020/10/31 - 10:41오전
현재 댓글 수정기능을 구현하고 있는데요.
while (rs.next()) { int commentsId = rs.getInt(1); String comment = rs.getString(2); String userName = rs.getString(3); String commentTime = rs.getString(4); %> <form name="commentForm" action="comment_modify_delete_ok.jsp"> <table> <tr> <td align="left" width="200" colspan="2"><b><%=userName %></b> <input type="hidden" name="commentsId" value="<%=commentsId %>"> <input type="hidden" name="postId" value="<%=idx %>"> </td> <% String commentsContents = "commentsContents" + commentsId; %> <td width="600" align="left" id="<%=commentsContents %>"><%=comment %></td> </tr> <tr> <td align="right" colspan="4"><%=commentTime %></td> </tr> <tr> <td colspan="50" align="right"> <input type="button" value="수정" name="delete" onClick="editComment('<%=commentsContents%>', '<%=comment%>')"> <input type="submit" value="삭제" name="delete"> </td> </tr> <tr height="1" bgcolor="#dddddd"><td colspan="4" width="407"></td></tr> </table> </form> <% }
댓글 부분 소스가 이렇고
수정버튼을 누르면
function editComment(commentsContents, comment) { document.getElementById(commentsContents).innerHTML = "<textarea cols=\"70\" rows=\"5\" id=\"comments\" name=\"comments\"></textarea><input type=\"submit\" value=\"등록\" name=\"delete\"><input type=\"button\" value=\"취소\" name=\"delete\" onClick=\"cancelEditComment('<\%=commentsContents\%>')\">"; document.getElementById('comments').innerText=comment; }
위 함수를 사용해서
<td width="600" align="left" id="<%=commentsContents %>"><%=comment %></td>
이부분 안쪽 html을 textarea로 변경해줍니다.
그리고 취소 버튼을 누르면
원상태로 돌아오게 하려고 하는데 잘 안되네요.
취소 버튼 클릭시 호출되는 함수는 다음과 같습니다.
function cancelEditComment(commentsContents) { alert('test'); document.getElementById(commentsContents).innerHTML = "<p></p>"; }
getElmentById 이 함수에서 문제가 발생하는데 왜 그런지 잘 모르겠습니다.
조언 좀 부탁드립니다.
html코드 변경하는건 포기하고 새로고침하는걸로 해결하였습니다.
Forums:
댓글 달기