seungmi

checkbox 웹페이지 양식 설정

웹페이지에서 checkbox입력을 할 수 있도록 설정
......@@ -4,7 +4,9 @@
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="/../style.css">
<title>Test</title>
<title>Test</title>
</head>
<body>
......@@ -22,25 +24,55 @@
<%= title %>
</h2>
<p><%= description %></p>
<form action='/food/recommendation' method='post'>
<button id='check_all'>모두 선택</button>
<button id='uncheck_all'>모두 해제</button>
<button id='count_check'>체크 수 확인</button>
<form action='/food/recommendation' method='post'>
<p>
가격 :
<input type="text" name="price" placeholder="price">
<input type="number" name="price" placeholder="price">
</p>
<p>
형태 :
<input type="text" name="shape" placeholder="밥, 빵, 면">
<input type="checkbox" name="shape" value="밥"></input>
<input type="checkbox" name="shape" value="면"></input>
<input type="checkbox" name="shape" value="고기">고기</input>
<input type="checkbox" name="shape" value="기타">기타</input>
</p>
<p>
종류 :
<input type="text" name="kinds" placeholder="한식, 중식, 일식, 양식">
<input type="checkbox" name="kinds" value="한식">한식</input>
<input type="checkbox" name="kinds" value="중식">중식</input>
<input type="checkbox" name="kinds" value="양식">양식</input>
<input type="checkbox" name="kinds" value="일식">일식</input>
</p>
<p>
<input type="submit">
</p>
</form>
<script src="//code.jquery.com/jquery.min.js"></script>
<script>
$("#check_all").click(function() {
$("input[name=kinds]:checkbox").prop("checked", "checked");
});
$("#uncheck_all").click(function() {
$("input[name=kinds]:checkbox").removeProp("checked");
});
$("#count_check").click(function() {
alert($("input[name=kinds]:checkbox:checked").length);
});
$("#check_all").click(function() {
$("input[name=shape]:checkbox").prop("checked", "checked");
});
$("#uncheck_all").click(function() {
$("input[name=shape]:checkbox").removeProp("checked");
});
$("#count_check").click(function() {
alert($("input[name=shape]:checkbox:checked").length);
});
</script>
</article>
</div class="grid">
......