jQuery SELECT 태그 관련 내용 > script

본문 바로가기
사이트 내 전체검색

script

jQuery SELECT 태그 관련 내용

페이지 정보

작성자 서방님 댓글 0건 조회 138회 작성일 12-09-24 16:13

본문

<?xml:namespace prefix = o />

jQuery로 선택된 값 읽기

$("#selectBox option:selected").val();

$("select[name=name]").val();

 

jQuery로 선택된 내용 읽기

$("#selectBox option:selected").text();

 

선택된 위치

var index = $("#test option").index($("#test option:selected"));

 

-------------------------------------------------------------------

 

// 뒤쪽에 옵션 추가

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

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

 

// 앞쪽에 옵션 삽입

$("#selectBox").prepend("<option value='0'>Before Apples</option>");

 

// 옵션 변경

$("#selectBox").html("<option value='1'>Some oranges</option><option value='2'>More Oranges</option>");

 

// 인덱스 위치에 따라 옵션 변경

$("#selectBox option:eq(1)").replaceWith("<option value='2'>Some apples</option>");

$("#selectBox option:eq(2)").replaceWith("<option value='3'>Some bananas</option>");

 

// 지정된 index 값으로 select 하기 (2번째 옵션 셀렉트)

$("#selectBox option:eq(2)").attr("selected", "selected");

 

// text 값으로 select 하기 (해당 텍스트를 가진 옵션 셀렉트)

$("#selectBox").val("Some oranges").attr("selected", "selected");

 

// value 값으로 select 하기 (해당값을 가진 옵션 셀렉트)

$("#selectBox").val("2");

 

// 지정된 인덱스 값의 item 삭제

$("#selectBox option:eq(0)").remove();

 

// 첫번째 item 삭제

$("#selectBox option:first").remove();

 

// 마지막 item 삭제

$("#selectBox option:last").remove();

 

// 선택된 옵션의 text 구하기

alert(!$("#selectBox option:selected").text());

 

// 선택된 옵션의 value 구하기

alert(!$("#selectBox option:selected").val());

 

// 선택된 옵션 index 구하기

alert(!$("#selectBox option").index($("#selectBox option:selected")));

 

// SelecBox 아이템 갯수 구하기

alert(!$("#selectBox option").size());

 

// 선택된 옵션 앞의 아이템 갯수

alert(!$("#selectBox option:selected").prevAl!l().size());

 

// 선택된 옵션 후의 아이템 갯수

alert(!$("#selectBox option:selected").nextAll().size());

 

// Insert an item in after a particular position

$("#selectBox option:eq(0)").after("<option value='4'>Some pears</option>");

 

// Insert an item in before a particular position

$("#selectBox option:eq(3)").before("<option value='5'>Some apricots</option>");

 

// Getting values when item is selected

$("#selectBox").change(function() {

           alert(!$(this).val());

           alert(!$(this).children("option:selected").text());

});

 

 

1. jQuery로 선택된 값 읽기

 

$("#selectBoxoption:selected").val();

$("select[name=name]").val();

 

2. jQuery로 선택된 내용 읽기

 

$("#selectBoxoption:selected").text();

 

3. 선택된 위치

 

var index =$("#test option").index($("#test option:selected"));

 

4. Addoptions to the end of a select

 

$("#selectBox").append("<optionvalue='1'>Apples</option>");

$("#selectBox").append("<optionvalue='2'>After Apples</option>");

 

5. Addoptions to the start of a select

 

$("#selectBox").prepend("<optionvalue='0'>Before Apples</option>");

 

6. Replaceall the options with new options

 

$("#selectBox").html("<optionvalue='1'>Some oranges</option><option value='2'>MoreOranges</option>");

 

7. Replaceitems at a certain index

 

$("#selectBoxoption:eq(1)").replaceWith("<option value='2'>Someapples</option>");

$("#selectBoxoption:eq(2)").replaceWith("<option value='3'>Somebananas</option>");

 

8. 지정된 index값으로 select 하기

 

$("#selectBoxoption:eq(2)").attr("selected", "selected");

 

9. text 값으로 select 하기

 

$("#selectBox").val("Someoranges").attr("selected", "selected");

 

10. value값으로 select 하기

 

$("#selectBox").val("2");

 

11. 지정된 인덱스값의 item 삭제

 

$("#selectBoxoption:eq(0)").remove();

 

12. 첫번째 item 삭제

 

$("#selectBoxoption:first").remove();

 

13. 마지막 item 삭제

 

$("#selectBoxoption:last").remove();

 

14. 선택된 옵션의 text 구하기

 

alert(!$("#selectBoxoption:selected").text());

 

15. 선택된 옵션의 value 구하기

 

alert(!$("#selectBoxoption:selected").val());

 

16. 선택된 옵션 index 구하기

 

alert(!$("#selectBoxoption").index($("#selectBox option:selected")));

 

17. SelecBox 아이템 갯수 구하기

 

alert(!$("#selectBoxoption").size());

 

18. 선택된 옵션 앞의 아이템 갯수

 

alert(!$("#selectBoxoption:selected").prevAl!l().size());

 

19. 선택된 옵션 후의 아이템 갯수

 

alert(!$("#selectBoxoption:selected").nextAll().size());

 

20. Insertan item in after a particular position

 

$("#selectBoxoption:eq(0)").after("<option value='4'>Somepears</option>");

 

21. Insertan item in before a particular position

 

$("#selectBoxoption:eq(3)").before("<option value='5'>Someapricots</option>");

 

22. Gettingvalues when item is selected

 

$("#selectBox").change(function(){

           alert(!$(this).val());

           alert(!$(this).children("option:selected").text());

});

댓글목록

등록된 댓글이 없습니다.

Total 846건 11 페이지
게시물 검색

회원로그인

접속자집계

오늘
83
어제
84
최대
1,347
전체
154,454
Latest Crypto Fear & Greed Index

그누보드5
Copyright © 서방님.kr All rights reserved.