본문 바로가기
카테고리 없음

[javascript] rowspan checkbox 체크시 모두 선택

by IT맥구리나스 2023. 2. 15.

개요

- rowspan checkbox 선택시 병합되어있는 행의 체크박스도 모두 체크 된다

 

코드

<table border=1>
  <tr>
    <td rowspan="2">
      <input type="checkbox" name="xxx" value="1" onclick="combat(this)"> 1 rows
    </td>
    <td>
      <input type="checkbox" name="2" value="2" id="check2">row 2
    </td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" name="3" value="3" id="check3">row 3
    </td>
  </tr>
</table>

<script>
  function combat(checkbox) {
    var check2 = document.getElementById("check2");
    var check3 = document.getElementById("check3");
    check2.checked = checkbox.checked;
    check3.checked = checkbox.checked;
  }
</script>

 

1 rows row 2
row 3

 

반응형

댓글