jQuery로 선택된 값 읽기
$("#select_box option:selected").val();
$("select[name=name]").val();
jQuery로 선택된 내용 읽기
$("#select_box option:selected").text();
선택된 위치
var index = $("#test option").index($("#test option:selected"));
-------------------------------------------------------------------
$("#myselect").append("<option value='1'>Apples</option>");
$("#myselect").append("<option value='2'>After Apples</option>");
// Add options to the start of a select
$("#myselect").prepend("<option value='0'>Before Apples</option>");
// Replace all the options with new options
$("#myselect").html("<option value='1'>Some oranges</option><option value='2'>More Oranges</option><option value='3'>Even more oranges</option>");
// Replace items at a certain index
$("#myselect option:eq(1)").replaceWith("<option value='2'>Some apples</option>");
$("#myselect option:eq(2)").replaceWith("<option value='3'>Some bananas</option>");
// Set the element at index 2 to be selected
$("#myselect option:eq(2)").attr("selected", "selected");
// Set the selected element by text
$("#myselect").val("Some oranges").attr("selected", "selected");
// Set the selected element by value
$("#myselect").val("2");
// Remove an item at a particular index
$("#myselect option:eq(0)").remove();
// Remove first item
$("#myselect option:first").remove();
// Remove last item
$("#myselect option:last").remove();
// Get the text of the selected item
alert($("#myselect option:selected").text());
// Get the value of the selected item
alert($("#myselect option:selected").val());
// Get the index of the selected item
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());
});
게시글 목록
| 번호 | 제목 |
|---|---|
| 10224 |
JavaScript
흔한 트위터,페이스북 퍼가기 자바스크립트
1
|
| 10217 |
Linux
리눅스 FFMPEG 자동실행소스(자작임)
6
|
| 17559 | |
| 10202 |
PHP
웹 소스 긁어오기
14
|
| 10201 | |
| 17557 | |
| 10198 |
Mobile
스마트폰에서 영상소스는?
2
|
| 19955 |
HTML
레이아웃이 비뚤합니다.
3
|
| 17556 | |
| 10195 |
정규표현식
정규식으로 html 태그 지우기
2
|
| 10192 |
jQuery
이미지 슬라이더 만들어보았습니다.
2
|
| 10190 |
jQuery
순차애니메이션 질문좀 드리겠습니다.
1
|
| 10189 | |
| 10186 | |
| 10185 | |
| 10182 | |
| 10180 | |
| 10178 |
node.js
node.js 0.8.2 번역 문서
1
|
| 10176 |
jQuery
CSS3처럼 이미지 라운딩 기능의 제이쿼리
1
|
| 10174 |
jQuery
이 플래시메뉴처럼 바꿔 만들려면...
1
|
| 10173 | |
| 10170 |
Mobile
가로 폭 문제
2
|
| 10168 |
MySQL
MySQL 테이블명 대소문자 구분안하기
1
|
| 10161 | |
| 10160 |
Flash
플래시 네비 관련
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기