close

Trust Me!! Trust You!!


  • Blog
  • Local Log
  • Tag Cloud
  • Key Log
  • Guestbook
  • RSS Feed
  • Write a Post
  • Admin

혹시 블로그 스킨이 깨져 보이시나요? 최신버전의 Internet Explorer(Windows용), Opera, Firefox를 사용해보세요.

[jQuery] Select Box 활용 노하우

웹 프로그래밍
2012/04/10 10:17
 

jQuery로 선택된 값 읽기

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

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

 

jQuery로 선택된 내용 읽기

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

 

선택된 위치

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

 

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

 

// Add options to the end of a select

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

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

 

// Add options to the start of a select

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

 

// Replace all the options with new options

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

 

// Replace items at a certain index

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

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

 

// 지정된 index 값으로 select 하기

$("#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").prevAll().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());

});

이올린에 북마크하기
No received trackback. / No comment.

Trackback Address :: http://viper150.cafe24.com/trackback/175

You can also say.

Prev 1 ... 125 126 127 128 129 130 131 132 133 ... 298 Next
블로그 이미지
이것저것 불펌금지도 퍼다가 담습니다. 외부에 비공개된 페이지 입니다. By. 어른왕자

카테고리

  • 전체 (298)
    • 사는 이야기 (115)
    • 웹 프로그래밍 (102)
    • App 프로그래밍 (22)
    • IT 뉴스&기타 (22)
    • 박한별 (4)
    • 역사&기타지식 (9)

태그목록

  • 달걀찜
  • hwpCtrl
  • 한예슬
  • 허성도
  • 생산성저하
  • 노트5
  • 남자성향
  • Javase
  • 전산공무원
  • getRealPath
  • ultraeditor
  • 우문술
  • 남성전용
  • 환상의 커플
  • 마우스
  • 의사결정
  • 서비스
  • CRC32
  • 날짜비교
  • Logparser
  • 자금지원
  • 수면부족
  • 웃김
  • Log
  • 일본
  • XSS
  • 몰카
  • 장애인
  • 텔레비젼
  • 생생정보통

최근에 올라온 글

  • 보험사의 조정신청 대응방법.
  • 어느 천재의 앞선 시선.
  • [병맛더빙] 누구게..... (1)
  • 韓경제 `회색 코뿔소` 상황...
  • SVN Connector 설치 URL.
  • 군대를 가지 않는 서울대생.
  • “운은 하늘의 귀여움 받는...
  • 목장에서 알바하다가 캐스...
  • [펌]믿고 거르는 관상.
  • 하루에 1세트씩 하면 좋다...

최근에 달린 댓글

  • <p align="center"><a href="h... 라임애드 02/14
  • <div style="OVERFLOW: hidden... 고사니 02/12
  • <p align="center"><a href="h... 라임정보 02/07
  • <p><img src="https://i.imgur... 브레드 01/22
  • <p><img src="https://i.imgur... 브레드 01/22

최근에 받은 트랙백

  • read this post from Bookie 7. read this post from Bookie 7 02/28
  • công ty may đồng phục. công ty may đồng phục 01/08
  • Israelnightclub`s recent blo... Israelnightclub`s recent blo.. 01/06
  • Suggested Browsing. Suggested Browsing 01/06
  • similar site. similar site 01/06

글 보관함

  • 2019/03 (1)
  • 2018/12 (1)
  • 2018/09 (1)
  • 2018/08 (1)
  • 2018/02 (1)

달력

«   2021/03   »
일 월 화 수 목 금 토
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

링크

  • Total : 263656
  • Today : 19
  • Yesterday : 41
Tattertools
Eolin
rss

어른왕자's blog is powered byTattertools1.1.2.2 : Animato