Javascript
[HTML & Javascript] radio 버튼으로 테이블 항목 바꾸기
HiroDaegu
2022. 1. 12. 21:35
728x90
SMALL


<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Change 'td' Javascript with radio button</title>
<style>
* {
text-align: center;
}
table {
border: 1px solid;
border-collapse: collapse;
margin: 0 auto;
width: 80%;
}
tr {
border: 1px solid;
border-collapse: collapse;
}
th {
border: 1px solid;
border-collapse: collapse;
}
td {
border: 1px solid;
border-collapse: collapse;
}
</style>
</head>
<body>
<br>
<br>
<br>
<input type="radio" name="open" value="col" checked onclick="changeLabel(this.value)"><label for="open">색깔</label>
<input type="radio" name="open" value="img" onclick="changeLabel(this.value)"><label for="open">이미지</label>
<br>
<br>
<br>
<br>
<table>
<colgroup>
<col width="20%">
<col width="80%">
</colgroup>
<tr>
<th>항목명</th>
<td colspan="3">값</td>
</tr>
<tr id="color">
<th>색깔</th>
<td colspan="3"><input type="color"></td>
</tr>
<tr id="img" style="display: none;">
<th>이미지</th>
<td colspan="3"><input type="file"></td>
</tr>
</table>
<script>
function changeLabel(value) {
if(value == "col") {
color.style.display = '';
img.style.display = 'none';
} else {
color.style.display = 'none';
img.style.display = '';
}
}
</script>
</body>
</html>728x90
LIST