리자

jQuery SELECT 태그 관련 내용

 
 
내용 좋네요 ^^y
[이 게시물은 관리자님에 의해 2011-10-31 16:55:28 jQuery에서 이동 됨]
|

댓글 1개

[펌]

// 뒤쪽에 옵션 추가

$("#myselect").append("<option value='1'>Apples</option>");
$("#myselect").append("<option value='2'>After Apples</option>");

// 앞쪽에 옵션 삽입
$("#myselect").prepend("<option value='0'>Before Apples</option>");

// 옵션변경
$("#myselect").html("<option value='1'>Some oranges</option><option value='2'>More Oranges</option><option value='3'>Even more oranges</option>");

// 인덱스 위치에 따라 옵션 변경
$("#myselect option:eq(1)").replaceWith("<option value='2'>Some apples</option>");
$("#myselect option:eq(2)").replaceWith("<option value='3'>Some bananas</option>");

// 2번째 옵션 셀렉트
$("#myselect option:eq(2)").attr("selected", "selected");

// 해당 텍스트를 가진 옵션 셀렉트
$("#myselect").val("Some oranges").attr("selected", "selected");

// 해당값을 가진 옵션 셀렉트
$("#myselect").val("2");

// 선택 옵션 제거
$("#myselect option:eq(0)").remove();

// 첫번째 옵션 제거
$("#myselect option:first").remove();

// 마지막 옵션 제거
$("#myselect option:last").remove();

// 셀렉트된 옵션 텍스트 리턴
alert($("#myselect option:selected").text());

// 셀렉트된 옵션 값리턴
alert($("#myselect option:selected").val());

// 셀렉트된 인덱스 리턴
alert($("#myselect option").index($("#myselect option:selected")));

// Alternative way to get the selected item
alert($("#myselect option:selected").prevAll().size());

// Insert an item in after a particular position
$("#myselect option:eq(0)").after("<option value='4'>Some pears</option>");

// Insert an item in before a particular position
$("#myselect option:eq(3)").before("<option value='5'>Some apricots</option>");

// Getting values when item is selected
$("#myselect").change(function() {
alert($(this).val());
alert($(this).children("option:selected").text());
});
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
14년 전 조회 2,138
14년 전 조회 2,484
14년 전 조회 1.1만
14년 전 조회 2,028
14년 전 조회 1,814
14년 전 조회 2,528
14년 전 조회 2,580
14년 전 조회 1,756
14년 전 조회 1,873
14년 전 조회 1,645
14년 전 조회 3,321
14년 전 조회 1,455
14년 전 조회 1,589
14년 전 조회 2,664
14년 전 조회 2,943
14년 전 조회 1,378
14년 전 조회 1,778
14년 전 조회 1,560
14년 전 조회 1,634
14년 전 조회 1,811
14년 전 조회 1,642
14년 전 조회 1,518
14년 전 조회 1,335
14년 전 조회 1,318
14년 전 조회 1,573
14년 전 조회 1,687
14년 전 조회 1,533
14년 전 조회 1,514
14년 전 조회 3,316
14년 전 조회 1,830
14년 전 조회 1,992
14년 전 조회 1,925
14년 전 조회 2,397
14년 전 조회 2,831
14년 전 조회 1,511
14년 전 조회 1,643
14년 전 조회 2,647
14년 전 조회 1,669
14년 전 조회 2,955
14년 전 조회 1,452
14년 전 조회 1,646
14년 전 조회 1,776
14년 전 조회 2,861
14년 전 조회 1,711
14년 전 조회 4,074
14년 전 조회 1,802
14년 전 조회 1,345
14년 전 조회 1,648
14년 전 조회 1,522
14년 전 조회 2,250
14년 전 조회 1,354
14년 전 조회 1,471
14년 전 조회 1,532
14년 전 조회 1,571
14년 전 조회 1,820
14년 전 조회 1,873
14년 전 조회 2,468
14년 전 조회 1,480
14년 전 조회 1,925
14년 전 조회 3,722
14년 전 조회 1,640
14년 전 조회 1,582
14년 전 조회 2,003
14년 전 조회 2,008
14년 전 조회 2,850
14년 전 조회 2,063
14년 전 조회 1,443
14년 전 조회 1,386
14년 전 조회 1,269
14년 전 조회 1,534
14년 전 조회 3,013
14년 전 조회 1,448
14년 전 조회 1,486
14년 전 조회 1,591
14년 전 조회 1,804
14년 전 조회 1,425
14년 전 조회 1,701
14년 전 조회 2,249
14년 전 조회 1,494
14년 전 조회 1,819
14년 전 조회 1,278
14년 전 조회 1,345
14년 전 조회 1,822
14년 전 조회 2,175
14년 전 조회 2,241
14년 전 조회 1,713
14년 전 조회 1,641
14년 전 조회 2,153
14년 전 조회 1,688
14년 전 조회 4,759
14년 전 조회 2,748
14년 전 조회 1,502
14년 전 조회 1,422
14년 전 조회 4,373
14년 전 조회 5,050
14년 전 조회 1,809
14년 전 조회 1,982
14년 전 조회 5,249
14년 전 조회 2,013
14년 전 조회 1,807