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());
});
게시글 목록
| 번호 | 제목 |
|---|---|
| 17819 |
JavaScript
당신이 알아야 할 자바스크립트의 강력한 7가지 팁
3
|
| 17818 |
JavaScript
자바스크립트 코드를 더 깔끔하고 보기 좋게 작성하는 팁
1
|
| 17817 |
PHP
chatgtp
|
| 17816 |
JavaScript
textarea 자동 높이 설정하기.
1
|
| 17814 | |
| 17811 |
JavaScript
자바스크립트 플래이그라운드 - RUNJS
|
| 17810 | |
| 17809 | |
| 17808 |
JavaScript
16진수 색상코드 확인함수
|
| 17803 | |
| 17799 | |
| 17798 | |
| 17797 |
JavaScript
동영상파일 썸네일 만들기
8
|
| 17795 |
JavaScript
div태그의 사이즈가 변경되는 이벤트를 처리하기
|
| 17794 |
JavaScript
초->hh:mm:ss로 변환하는 함수
1
|
| 17793 |
JavaScript
JSON Beautify
|
| 17790 |
PHP
JSONP실례
|
| 17789 | |
| 17786 |
JavaScript
ThreeJS로 3디지구에 포인트 찍고 정보 현시기능
|
| 17774 | |
| 17760 | |
| 17755 | |
| 17750 | |
| 17729 | |
| 17722 | |
| 17714 | |
| 17708 | |
| 17686 | |
| 17676 |
JavaScript
유튜브 풀화면 묵음배경 예제
9
|
| 17666 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기