seungmi

checkbox 웹페이지 양식 설정

웹페이지에서 checkbox입력을 할 수 있도록 설정
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
4 <head> 4 <head>
5 <meta charset="utf-8"> 5 <meta charset="utf-8">
6 <link rel="stylesheet" href="/../style.css"> 6 <link rel="stylesheet" href="/../style.css">
7 -<title>Test</title> 7 + <title>Test</title>
8 +
9 +
8 </head> 10 </head>
9 11
10 <body> 12 <body>
...@@ -22,25 +24,55 @@ ...@@ -22,25 +24,55 @@
22 <%= title %> 24 <%= title %>
23 </h2> 25 </h2>
24 <p><%= description %></p> 26 <p><%= description %></p>
25 - <form action='/food/recommendation' method='post'> 27 +
28 + <button id='check_all'>모두 선택</button>
29 + <button id='uncheck_all'>모두 해제</button>
30 + <button id='count_check'>체크 수 확인</button>
26 31
32 + <form action='/food/recommendation' method='post'>
27 <p> 33 <p>
28 가격 : 34 가격 :
29 - <input type="text" name="price" placeholder="price"> 35 + <input type="number" name="price" placeholder="price">
30 </p> 36 </p>
31 <p> 37 <p>
32 - 형태 : 38 + <input type="checkbox" name="shape" value="밥"></input>
33 - <input type="text" name="shape" placeholder="밥, 빵, 면"> 39 + <input type="checkbox" name="shape" value="면"></input>
40 + <input type="checkbox" name="shape" value="고기">고기</input>
41 + <input type="checkbox" name="shape" value="기타">기타</input>
34 </p> 42 </p>
35 <p> 43 <p>
36 - 종류 : 44 + <input type="checkbox" name="kinds" value="한식">한식</input>
37 - <input type="text" name="kinds" placeholder="한식, 중식, 일식, 양식"> 45 + <input type="checkbox" name="kinds" value="중식">중식</input>
46 + <input type="checkbox" name="kinds" value="양식">양식</input>
47 + <input type="checkbox" name="kinds" value="일식">일식</input>
38 </p> 48 </p>
39 <p> 49 <p>
40 <input type="submit"> 50 <input type="submit">
41 </p> 51 </p>
42 -
43 </form> 52 </form>
53 +
54 +
55 + <script src="//code.jquery.com/jquery.min.js"></script>
56 + <script>
57 + $("#check_all").click(function() {
58 + $("input[name=kinds]:checkbox").prop("checked", "checked");
59 + });
60 + $("#uncheck_all").click(function() {
61 + $("input[name=kinds]:checkbox").removeProp("checked");
62 + });
63 + $("#count_check").click(function() {
64 + alert($("input[name=kinds]:checkbox:checked").length);
65 + });
66 + $("#check_all").click(function() {
67 + $("input[name=shape]:checkbox").prop("checked", "checked");
68 + });
69 + $("#uncheck_all").click(function() {
70 + $("input[name=shape]:checkbox").removeProp("checked");
71 + });
72 + $("#count_check").click(function() {
73 + alert($("input[name=shape]:checkbox:checked").length);
74 + });
75 + </script>
44 </article> 76 </article>
45 </div class="grid"> 77 </div class="grid">
46 78
......