[SCRIPT] 스크립트로 select option 변경/선택 (prop 사용)
2018.04.06
작성일/수정일
2018-04-06 14:20:11 / 2018-04-06 14:20:11
1. 이벤트 내 함수로 변경
$("#id").on("change", function(){
// value 값으로 선택
$(this).val("1").prop("selected", true);
// option 순서값으로 선택
$(this).find("option:eq(1)").prop("selected", true);
});
2. 스크립트에서 변경
// value 값으로 선택
$("#select_id").val("1").prop("selected", true);
// option 순서값으로 선택
$("#select_id option:eq(1)").prop("selected", true);
attr 도 사용가능 (단, 스크립트로 추가된 속성은 변경이 불가)
** 이런식으로도 사용 가능
-> $(this).prop('checked', true);
-> $(this).attr('disabled', true);
-> $(this).attr('disabled', true).prop('checked', true);