기본 콘텐츠로 건너뛰기

1월, 2014의 게시물 표시

2022 08 26 회사 워크샵

jQuery selectBox 제어하기

jQuery로 선택된 값 읽기 $("#selectBox option:selected").val(); $("#select_box > option:selected").val() $("select[name=name]").val(); jQuery로 선택된 내용 읽기 $("#selectBox option:selected").text(); 선택된 위치 var index = $("#test option").index($("#test option:selected")); ------------------------------------------------------------------- // Add options to the end of a select $("#selectBox").append("<option value='1'>Apples</option>"); $("#selectBox").append("<option value='2'>After Apples</option>"); // Add options to the start of a select $("#selectBox").prepend("<option value='0'>Before Apples</option>"); // Replace all the options with new options $("#selectBox") .html("<option value='1'>oranges</option><option value='2'>Oranges</option>"