리자

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,078
14년 전 조회 2,425
14년 전 조회 1.1만
14년 전 조회 1,967
14년 전 조회 1,748
14년 전 조회 2,464
14년 전 조회 2,521
14년 전 조회 1,688
14년 전 조회 1,796
14년 전 조회 1,587
14년 전 조회 3,262
14년 전 조회 1,394
14년 전 조회 1,528
14년 전 조회 2,599
14년 전 조회 2,884
14년 전 조회 1,323
14년 전 조회 1,704
14년 전 조회 1,491
14년 전 조회 1,578
14년 전 조회 1,756
14년 전 조회 1,571
14년 전 조회 1,455
14년 전 조회 1,282
14년 전 조회 1,266
14년 전 조회 1,523
14년 전 조회 1,628
14년 전 조회 1,478
14년 전 조회 1,458
14년 전 조회 3,271
14년 전 조회 1,759
14년 전 조회 1,927
14년 전 조회 1,872
14년 전 조회 2,343
14년 전 조회 2,766
14년 전 조회 1,453
14년 전 조회 1,584
14년 전 조회 2,604
14년 전 조회 1,615
14년 전 조회 2,913
14년 전 조회 1,398
14년 전 조회 1,609
14년 전 조회 1,724
14년 전 조회 2,817
14년 전 조회 1,661
14년 전 조회 4,023
14년 전 조회 1,752
14년 전 조회 1,298
14년 전 조회 1,601
14년 전 조회 1,470
14년 전 조회 2,205
14년 전 조회 1,310
14년 전 조회 1,424
14년 전 조회 1,488
14년 전 조회 1,531
14년 전 조회 1,778
14년 전 조회 1,826
14년 전 조회 2,416
14년 전 조회 1,424
14년 전 조회 1,864
14년 전 조회 3,667
14년 전 조회 1,580
14년 전 조회 1,540
14년 전 조회 1,951
14년 전 조회 1,958
14년 전 조회 2,801
14년 전 조회 2,022
14년 전 조회 1,398
14년 전 조회 1,341
14년 전 조회 1,227
14년 전 조회 1,489
14년 전 조회 2,969
14년 전 조회 1,412
14년 전 조회 1,438
14년 전 조회 1,531
14년 전 조회 1,752
14년 전 조회 1,376
14년 전 조회 1,645
14년 전 조회 2,200
14년 전 조회 1,449
14년 전 조회 1,769
14년 전 조회 1,231
14년 전 조회 1,302
14년 전 조회 1,774
14년 전 조회 2,138
14년 전 조회 2,193
14년 전 조회 1,666
14년 전 조회 1,598
14년 전 조회 2,121
14년 전 조회 1,653
14년 전 조회 4,717
14년 전 조회 2,697
14년 전 조회 1,459
14년 전 조회 1,373
14년 전 조회 4,327
14년 전 조회 5,004
14년 전 조회 1,768
14년 전 조회 1,933
14년 전 조회 5,206
14년 전 조회 1,979
14년 전 조회 1,774