program

[jQuery] 라디오(radio) 버튼, 체크박스(checkbox) 선택/해제 하는 방법

littlecarbb 2018. 9. 30. 16:49

[예 1 - 라디오버튼]


HTML

<label><input type="radio" name="fruits" value="사과">사과</label>

<label><input type="radio" name="fruits" value="복숭아">복숭아</label>


Javascript

$("input:radio[name='fruits']:radio[value='사과']").prop('checked', true); // 선택하기

$("input:radio[name='fruits']:radio[value='사과']").prop('checked', false); // 해제하기





[예 1 - 체크박스]


HTML

<label><input type="checkbox" name="fruits" value="사과">사과</label>

<label><input type="checkbox" name="fruits" value="복숭아">복숭아</label>

<label><input type="checkbox" name="fruits" value="포도">포도</label>
<label><input type="checkbox" name="fruits" value="참외">참외</label>


Javascript

$("checkbox[name='fruits']").prop('checked', true); // 전체선택하기

$("checkbox[name='fruits']").prop('checked', false); // 전체해제하기