2018년 12월 6일 목요일

JavaScript - checkbox






[체크박스 전체 선택/해제]


<table>
  <colgroup>
     <col width="50" />
  </colgroup>
  <tr>
    <th><input type="checkbox" class="ckall" onclick="ckall(this)" /></th>
    <th>제목</th>
  </tr>
  <tr>
    <td><input type="checkbox" /></td>
    <td>무한도전</td>
  </tr>
  <tr>
    <td><input type="checkbox" /></td>
     <td>세바퀴</td>
  </tr>
  <tr>
    <td><input type="checkbox" /></td>
    <td>1박2일</td>
  </tr>
</table>



function ckall(o){
  var ck = $(o).prop("checked");  // 선택한 체크박스의 상태가 checked 이면 true 아니면 false를 반환합니다.
  if(ck){  // true 이면
    $("table input").prop("checked", true); //table 안에 포함된 input 상태값을 체크한다.
  }else{ // false 이면
    $("table input").prop("checked", false); //table 안에 포함된 input 상태값을 체크해제한다.
  }
}



function ckall(o){
  var ck = $(o).prop("checked");  // 선택한 체크박스의 상태가 checked 이면 true 아니면 false를 반환합니다.
  $("table input").prop("checked", ck); //table 안에 포함된 input 상태값을 체크
}




댓글 없음:

댓글 쓰기

javascript - SQL 예약어 제거

  <script language="javascript"> //특수문자, 특정문자열(sql예약어) 제거 function checkSearchedWord(obj){ obj.value = obj.value+&quo...