dev/jquery

html checkbox 값 설정

strange-dev 2024. 9. 22. 10:56
반응형
html radio 값 설정
<input type="checkbox" id="chk0" name="chk0" /><label for="chk0">일</label>
<input type="checkbox" id="chk1" name="chk1" /><label for="chk1">월</label>
<input type="checkbox" id="chk2" name="chk2" /><label for="chk2">화</label>
<input type="checkbox" id="chk3" name="chk3" /><label for="chk3">수</label>
<input type="checkbox" id="chk4" name="chk4" /><label for="chk4">목</label>
<input type="checkbox" id="chk5" name="chk5" /><label for="chk5">금</label>
<input type="checkbox" id="chk6" name="chk6" /><label for="chk6">토</label>
  • 위처럼 checkbox 가 있을 경우 간단한 선택 방법입니다
$(function () {
    // javascript
    document.getElementById('chk5').checked = true;
    // jquery
    $('#chk6').prop('checked', true);
});

 

javascript
  • document.getElementById('checkbox아이디'). checked = true;

jquery
  • $('#checkbox아이디' '). prop('checked', true);
반응형