Form관련 jQuery 선택기 명령어 - :selected (드롭다운리스트에서 선택한 값 가져오기)
.NET프로그래밍/jQuery 1.3.2 2009. 11. 9. 12:02 |
[Selected.htm]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>드롭다운리스트 선택한 값 가져오기</title>
<script src="../js/jquery-1.3.2-vsdoc2.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
// 콤보박스가 변경될 때
$('#lstFavorites').change(function () {
// 드롭다운리스트에서 선택된 값을 텍스트박스에 출력
var selectedText = // $("#lstFavorites option:selected").text();
// $("option:selected").text();
$(":selected").text();
$('#txtFavorite').val(selectedText);
});
});
</script>
</head>
<body>
<select id="lstFavorites">
<option>C#</option>
<option>ASP.NET</option>
<option>Silverlight</option>
</select>
<hr />
<input type="text" id="txtFavorite" />
</body>
</html>
-------------------------------------------------------------------------------------
[실행결과]
--> 아래그림에서 "드롭다운리스트"에서 선택한대로 드롭다운리스트 아래에 있는 "텍스트박스"에 드롭다운리스트와 같은 값이 출력된다.
'.NET프로그래밍 > jQuery 1.3.2' 카테고리의 다른 글
Attributes - 마우스 오버시 큰 이미지 보여주기 (1) | 2009.11.10 |
---|---|
Attributes - DOM요소의 attribute 읽어오기 (0) | 2009.11.09 |
Form관련 jQuery 선택기 명령어 - 암호확인(PasswordConfirm) 기능 구현하기 (0) | 2009.11.09 |
Form관련 jQuery 선택기 명령어 - :text (텍스트박스의 값 복사) (0) | 2009.11.09 |
Form관련 jQuery 선택기 명령어 - :input (모든 폼 요소 읽어오기) (0) | 2009.11.09 |