리자

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년 전 조회 1,248
14년 전 조회 1,592
14년 전 조회 1만
14년 전 조회 1,123
14년 전 조회 930
14년 전 조회 1,645
14년 전 조회 1,686
14년 전 조회 859
14년 전 조회 963
14년 전 조회 776
14년 전 조회 2,404
14년 전 조회 567
14년 전 조회 720
14년 전 조회 1,779
14년 전 조회 2,061
14년 전 조회 507
14년 전 조회 892
14년 전 조회 668
14년 전 조회 733
14년 전 조회 928
14년 전 조회 743
14년 전 조회 646
14년 전 조회 468
14년 전 조회 437
14년 전 조회 670
14년 전 조회 814
14년 전 조회 633
14년 전 조회 618
14년 전 조회 2,432
14년 전 조회 938
14년 전 조회 1,089
14년 전 조회 1,067
14년 전 조회 1,507
14년 전 조회 1,900
14년 전 조회 594
14년 전 조회 762
14년 전 조회 1,807
14년 전 조회 796
14년 전 조회 2,094
14년 전 조회 580
14년 전 조회 783
14년 전 조회 898
14년 전 조회 2,013
14년 전 조회 832
14년 전 조회 3,194
14년 전 조회 962
14년 전 조회 487
14년 전 조회 825
14년 전 조회 676
14년 전 조회 1,354
14년 전 조회 527
14년 전 조회 640
14년 전 조회 685
14년 전 조회 713
14년 전 조회 985
14년 전 조회 1,027
14년 전 조회 1,602
14년 전 조회 629
14년 전 조회 1,079
14년 전 조회 2,867
14년 전 조회 790
14년 전 조회 744
14년 전 조회 1,180
14년 전 조회 1,175
14년 전 조회 2,016
14년 전 조회 1,226
14년 전 조회 598
14년 전 조회 550
14년 전 조회 445
14년 전 조회 664
14년 전 조회 2,174
14년 전 조회 611
14년 전 조회 636
14년 전 조회 729
14년 전 조회 935
14년 전 조회 577
14년 전 조회 857
14년 전 조회 1,425
14년 전 조회 657
14년 전 조회 967
14년 전 조회 437
14년 전 조회 503
14년 전 조회 982
14년 전 조회 1,326
14년 전 조회 1,395
14년 전 조회 869
14년 전 조회 796
14년 전 조회 1,327
14년 전 조회 842
14년 전 조회 3,934
14년 전 조회 1,868
14년 전 조회 673
14년 전 조회 597
14년 전 조회 3,541
14년 전 조회 4,224
14년 전 조회 964
14년 전 조회 1,159
14년 전 조회 4,389
14년 전 조회 1,202
14년 전 조회 992
🐛 버그신고