안규 공부방

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>
※ 혹시 도움이 되셨다면 댓글에 한마디 남겨주세요!
작성자   비밀번호
자동글 방지     (자동글 방지 기능입니다.)
내용   댓글달기 
이메일 문의 : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.