Javascript & JQuery & CSS > example - 체크박스 클릭 시 해당 테이블(table) 줄(tr) 배경색 변경하기
등록일 : 2020-12-17 12:18
조회수 : 94,317
<script>
function setBg(t) {
td = t.parentNode;
td.style.backgroundColor = (t.checked) ? "blue" : "white";
tr = t.parentNode.parentNode;
tr.style.backgroundColor = (t.checked) ? "#FFBB00" : "#fff";
}
</script>
</head>
<body>
<table width="100%;" border=1 cellspacing=0 cellpadding=5>
<tr>
<td width=20><input type="checkbox" onclick="setBg(this)"></td>
<td>체크박스1</td>
</tr>
<tr>
<td><input type="checkbox" onclick="setBg(this)"></td>
<td>체크박스2</td>
</tr>
<tr>
<td><input type="checkbox" onclick="setBg(this)"></td>
<td>체크박스3</td>
</tr>
</table>
</body>
</html>