我想知道如何在每次更改值組合框時獲取所選選項的值。這裏是我的代碼:如何使用javascript獲取html選擇值?
<html>
<head>
<script type="text/javascript">
function dispOptionValue() {
var select = document.getElementById('footballPlayers');
alert(select.options.value);
}
</script>
</head>
<body>
<select id="footballPlayers" onchange="dispOptionValue">
<option value="1">Ricardo Kaka</option>
<option value="2">Cristiano Ronaldo</option>
<option value="3">Johan Crujjf</option>
<option value="4">Gerd Muller</option>
<option value="5">Franz Beckenbauer</option>
</select>
</body>
</html>
我知道它錯了,但我不知道如何開始。請幫助。提前致謝。
非常感謝。如果我想獲得選項的內容,我該怎麼做呢? – NinjaBoy
啊好吧我已經得到它我只需要做select.options [select.selectedIndex] .innerHTML – NinjaBoy