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());
});
게시글 목록
| 번호 | 제목 |
|---|---|
| 19947 |
HTML
DIV의 justify 정렬 문제
7
|
| 10159 |
JavaScript
ie 에서는 되는데 크롬에서는 왜 안될까요?
|
| 10158 | |
| 19944 | |
| 10155 | |
| 10154 |
jQuery
이미지 슬라이드 질문 드립니다.
|
| 10152 |
Mobile
모바일 페이지 확대 축소 도움부탁려요
1
|
| 10151 | |
| 10148 |
JavaScript
HTTP 로그인 인증창에 대해 질문합니다 도와주세요ㅠㅠ
2
|
| 17555 | |
| 10146 | |
| 19939 | |
| 10143 |
JavaScript
자바에서...
2
|
| 10141 | |
| 10135 |
JavaScript
list.skin.php에서 자바스크립트 출력 문제 입니다.
5
|
| 10132 | |
| 10131 |
Mobile
모바일 사이트는 웹표준 코딩 할려면 어떻게 하나요
|
| 10126 |
JavaScript
JScript.Encode 복호화 방법
4
|
| 10122 |
MySQL
db 값이 가끔 안넘어가는경우가.....
3
|
| 10120 | |
| 10113 | |
| 10107 |
jQuery
메인 탭 롤링 배너 입니다.
5
|
| 10104 |
JavaScript
jQuery 쉽게 참고 할만한 사이트 없나요?
2
|
| 10103 |
node.js
NodeJS 추천사이트
|
| 10100 |
JavaScript
팝업창 관련 질문드려요!
2
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기