jQuery로 선택된 값 읽기
jQuery("#selectBox
option:selected").val();
jQuery("select[name=name]").val();
jQuery로 선택된 내용 읽기
jQuery("#selectBox
option:selected").text();
선택된 위치
var index
= jQuery("#test option").index(jQuery("#test
option:selected"));
-------------------------------------------------------------------
// Add options to the end of a select
jQuery("#selectBox").append("<option
value='1'>Apples</option>");
jQuery("#selectBox").append("<option
value='2'>After Apples</option>");
// Add options to the start of a select
jQuery("#selectBox").prepend("<option
value='0'>Before Apples</option>");
// Replace all the options with new
options
jQuery("#selectBox").html("<option
value='1'>Some oranges</option><option value='2'>More
Oranges</option>");
// Replace items at a certain index
jQuery("#selectBox
option:eq(1)").replaceWith("<option
value='2'>Some apples</option>");
jQuery("#selectBox
option:eq(2)").replaceWith("<option
value='3'>Some bananas</option>");
// 지정된 index 값으로 select 하기
jQuery("#selectBox
option:eq(2)").attr("selected", "selected");
// text 값으로 select 하기
jQuery("#selectBox").val("Some
oranges").attr("selected", "selected");
// value 값으로 select 하기
jQuery("#selectBox").val("2");
// 지정된 인덱스 값의 item 삭제
jQuery("#selectBox
option:eq(0)").remove();
// 첫번째 item 삭제
jQuery("#selectBox
option:first").remove();
// 마지막 item 삭제
jQuery("#selectBox
option:last").remove();
// 선택된 옵션의 text 구하기
alert(jQuery("#selectBox
option:selected").text());
// 선택된 옵션의 value 구하기
alert(jQuery("#selectBox
option:selected").val());
// 선택된 옵션 index 구하기
alert(jQuery("#selectBox
option").index(jQuery("#selectBox
option:selected")));
// SelecBox 아이템 갯수 구하기
alert(jQuery("#selectBox
option").size());
// 선택된 옵션 앞의 아이템 갯수
alert(jQuery("#selectBox
option:selected").prevAll().size());
// 선택된 옵션 후의 아이템 갯수
alert(jQuery("#selectBox
option:selected").nextAll().size());
// Insert an item in after a particular
position
jQuery("#selectBox
option:eq(0)").after("<option
value='4'>Some pears</option>");
// Insert an item in before a particular
position
jQuery("#selectBox
option:eq(3)").before("<option
value='5'>Some apricots</option>");
// Getting values when item is selected
jQuery("#selectBox").change(function() {
alert(jQuery(this).val());
alert(jQuery(this).children("option:selected").text());
});