프리랜서 웹디자이너 웹퍼블리셔RELATION

RELATION 로고

홈페이지 소스

[SCRIPT] 스크립트로 select option 변경/선택 (prop 사용)

2018.04.06
북마크 [출처 이동]    작성자 정보
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);



이 포스트 공유하기

전체목록