리자

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,052
14년 전 조회 2,388
14년 전 조회 1.1만
14년 전 조회 1,926
14년 전 조회 1,717
14년 전 조회 2,426
14년 전 조회 2,478
14년 전 조회 1,643
14년 전 조회 1,757
14년 전 조회 1,549
14년 전 조회 3,226
14년 전 조회 1,361
14년 전 조회 1,487
14년 전 조회 2,561
14년 전 조회 2,846
14년 전 조회 1,292
14년 전 조회 1,678
14년 전 조회 1,459
14년 전 조회 1,547
14년 전 조회 1,723
14년 전 조회 1,550
14년 전 조회 1,421
14년 전 조회 1,245
14년 전 조회 1,238
14년 전 조회 1,484
14년 전 조회 1,592
14년 전 조회 1,448
14년 전 조회 1,427
14년 전 조회 3,245
14년 전 조회 1,720
14년 전 조회 1,898
14년 전 조회 1,850
14년 전 조회 2,314
14년 전 조회 2,743
14년 전 조회 1,424
14년 전 조회 1,555
14년 전 조회 2,563
14년 전 조회 1,580
14년 전 조회 2,892
14년 전 조회 1,374
14년 전 조회 1,580
14년 전 조회 1,690
14년 전 조회 2,795
14년 전 조회 1,639
14년 전 조회 3,996
14년 전 조회 1,721
14년 전 조회 1,268
14년 전 조회 1,565
14년 전 조회 1,434
14년 전 조회 2,176
14년 전 조회 1,278
14년 전 조회 1,397
14년 전 조회 1,465
14년 전 조회 1,506
14년 전 조회 1,749
14년 전 조회 1,792
14년 전 조회 2,374
14년 전 조회 1,386
14년 전 조회 1,834
14년 전 조회 3,633
14년 전 조회 1,551
14년 전 조회 1,518
14년 전 조회 1,928
14년 전 조회 1,935
14년 전 조회 2,770
14년 전 조회 1,999
14년 전 조회 1,369
14년 전 조회 1,315
14년 전 조회 1,200
14년 전 조회 1,457
14년 전 조회 2,940
14년 전 조회 1,382
14년 전 조회 1,415
14년 전 조회 1,500
14년 전 조회 1,728
14년 전 조회 1,354
14년 전 조회 1,622
14년 전 조회 2,175
14년 전 조회 1,428
14년 전 조회 1,744
14년 전 조회 1,205
14년 전 조회 1,282
14년 전 조회 1,752
14년 전 조회 2,108
14년 전 조회 2,168
14년 전 조회 1,639
14년 전 조회 1,573
14년 전 조회 2,093
14년 전 조회 1,626
14년 전 조회 4,694
14년 전 조회 2,665
14년 전 조회 1,435
14년 전 조회 1,358
14년 전 조회 4,301
14년 전 조회 4,980
14년 전 조회 1,744
14년 전 조회 1,911
14년 전 조회 5,170
14년 전 조회 1,953
14년 전 조회 1,742