Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- find
- plugin
- 네트워크
- netsh
- grep
- VirtualBox
- 단축키
- JavaScript
- web.xml
- Quartz
- ssh
- 줄바꿈 문자
- vscode
- GIT
- import
- profile
- Eclipse
- bash
- port
- Mac
- IntelliJ
- maVen
- Windows
- lsof
- resource
- Windows 10
- context
- Source
- tomcat
- xargs
Archives
- Today
- Total
develog
[html] form, checkbox 본문
<input type="checkbox" id="chk1" name="color" value="red">
<label for="chk1">red</label><br>
<input type="checkbox" id="chk2" name="color" value="green">
<label for="chk2">green</label><br>
<input type="checkbox" id="chk3" name="color" value="blue">
<label for="chk3">blue</label><br>
<button class="btn1">check all</button>
<button class="btn2">uncheck all</button>
<button class="btn3">checked values</button>
<div class="output"></div>
.output {
border: 1px solid lightgray;
height: 20px;
}
document.addEventListener('DOMContentLoaded', function(e) {
var btn1 = document.querySelectorAll('.btn1')[0];
var btn2 = document.querySelectorAll('.btn2')[0];
var btn3 = document.querySelectorAll('.btn3')[0];
btn1.addEventListener('click', function(e) {
document.querySelectorAll('input[name=color]').forEach(function(e) {
e.checked = true;
});
});
btn2.addEventListener('click', function(e) {
document.querySelectorAll('input[name=color]').forEach(function(e) {
e.checked = false;
});
});
btn3.addEventListener('click', function(e) {
document.querySelectorAll('.output')[0].innerHTML = '';
document.querySelectorAll('input[name=color]').forEach(function(e) {
if (e.checked) {
document.querySelectorAll('.output')[0].innerHTML += e.value + ' ';
}
});
});
});
Comments