<pre class="brush: js">
console.info("Hello");
</pre>
홈페이지를 만들다보면 form을 전송하는 경우가 많다.
이 때, form들이 중복되는 코드가 많을 경우에는 어떻게 할까?
script를 이용하자.
<pre class = "brush:js">
console.info("Hello");
</pre>
/*-------JSP-----------------------*/
<form role="form" action="modifyPage" method="post">
<input type='hidden' name='bno' value="${boardVO.bno}"> <input
type='hidden' name='page' value="${cri.page}"> <input
type='hidden' name='perPageNum' value="${cri.perPageNum}">
<input type='hidden' name='searchType' value="${cri.searchType}">
<input type='hidden' name='keyword' value="${cri.keyword}">
</form>
<button type="submit" class="btn btn-warning">Modify</button>
<button type="submit" class="btn btn-danger">REMOVE</button>
<button type="submit" class="btn btn-default" id = "GO_LIST">GO LIST</button>
<script>
$(document).ready(function(){
var formObj = $("form[role='form']");
console.log(formObj);
$(".btn-warning").on("click", function() {
formObj.attr("action", "/sboard/modifyPage");
formObj.attr("method", "get");
formObj.submit();
});
$(".btn-danger").on("click", function() {
formObj.attr("action", "/sboard/removePage");
formObj.submit();
});
$("#GO_LIST").on("click", function() {
formObj.attr("method", "get");
formObj.attr("action", "/sboard/list");
formObj.submit();
});
});
</script>
</pre>