jsp를 수정해 댓글 수정창을 만든다
<!-- 댓글 목록 -->
<form action="/board/addReply.kh" method="post">
<input type="hidden" name="refBoardNo" value="${board.boardNo }">
<table align="center" width="500" border="1">
<tr>
<td><textarea rows="3" cols="55" placeholder="내용을 작성하세요"
name="replyContents" required="required"></textarea></td>
<td>
<button>등록하기</button>
</td>
</tr>
</table>
</form>
<table align="center" width="500" border="1">
<c:forEach items="${rList }" var="reply" varStatus="i">
<tr>
<td width="100">${reply.replyWirter }</td>
<td>${reply.replyContents }</td>
<td>${reply.rCreateDate }</td>
<td><button type="button" onclick="modifyView(this.id)"
id="modify${i.count }">수정</button> <a href="#">삭제</a>
</tr>
<!--여기부터 댓글 수정창-->
<tr class="modifyViews">
<form action="/board/" method="post">
<td colspan="3"><input type="hidden" name="replyNo"
value="${reply.replyNo }"> <input type="hidden"
name="refBoardNo" value="${board.boardNo }"> <textarea
rows="3" cols="55" placeholder="내용을 작성하세요" name="replyContents"
required="required">
${reply.replyContents }
</textarea></td>
<td>
<button>수정</button>
<button onclick="modifyCancle('modify${i.count }')" type="button">취소</button>
</td>
</form>
</tr>
<!--댓글 수정창 종료-->
</c:forEach>
</table>
</form>
<script>
var modifyViews = document.getElementsByClassName('modifyViews')
for (var i = 0; i < modifyViews.length; i++) {
modifyViews[i].style.display = 'none'
}
function modifyCancle(idI) {
var modifiId = document.getElementById(idI);
modifiId.parentElement.parentElement.style.display = '';
modifiId.parentElement.parentElement.nextElementSibling.style.display = 'none';
}
function modifyView(idI) {
var modifiId = document.getElementById(idI);
modifiId.parentElement.parentElement.style.display = 'none';
modifiId.parentElement.parentElement.nextElementSibling.style.display = '';
}
function remove() {
event.preventDefault(); // 하이퍼링크 이동방지
if (window.confirm("게시물을 삭제하시겠습니까?")) {
location.href = '/board/remove.kh?page=${pageNow}';
}
}
</script>
var modifyViews = document.getElementsByClassName('modifyViews')
for (var i = 0; i < modifyViews.length; i++) {
modifyViews[i].style.display = 'none'
}
<c:forEach items="${rList }" var="reply" varStatus="i">
<tr>
<td width="100">${reply.replyWirter }</td>
<td>${reply.replyContents }</td>
<td>${reply.rCreateDate }</td>
<td><button type="button" onclick="modifyView(this.id)"
id="modify${i.count }">수정</button> <a href="#">삭제</a>
</tr>
function modifyView(idI) {
var modifiId = document.getElementById(idI);
modifiId.parentElement.parentElement.style.display = 'none';
modifiId.parentElement.parentElement.nextElementSibling.style.display = '';
}
<tr>
<form action="/board/" method="post">
<td colspan="3"><input type="hidden" name="replyNo"
value="${reply.replyNo }"> <input type="hidden"
name="refBoardNo" value="${board.boardNo }"> <textarea
rows="3" cols="55" placeholder="내용을 작성하세요" name="replyContents"
required="required">
${reply.replyContents }
</textarea></td>
<td>
<button>수정</button>
<button onclick="modifyCancle('modify${i.count }')" type="button">취소</button>
</td>
</form>
</tr>
function modifyCancle(idI) {
var modifiId = document.getElementById(idI);
modifiId.parentElement.parentElement.style.display = '';
modifiId.parentElement.parentElement.nextElementSibling.style.display = 'none';
}