본문 바로가기

프로그래밍/jQuery

jQuery select box 값 설정 및 가져오기

<script type="text/javascript">
$(document).ready(function(){
$("#selectListButton1").click(function(){
alert( 'Value is: ' + $('#selectList').val() );
});
$("#selectListButton2").click(function(){
alert( 'Text is: ' + $('#selectList :selected').text() );
});
});
</script>



<select id="selectList">
<option value="1">First Option</option>
<option value="2">Second Option</option>
<option value="3">Third Option</option>
</select>

<button id="selectListButton1">Get Value</button>
<button id="selectListButton2">Get Text</button>