我有以下代碼。但警報不顯示選項的名稱,而是顯示「未定義」。對於價值,它顯示正確的內容。未定義的選項名稱javascript
<select id="test" name="select_decision" onchange="javascript:
var activeText = this.options[this.selectedIndex].value
var activeOption = this.options[this.selectedIndex].name;
alert(activeOption);
">
一個選項的一個例子是:
<option value="test" name="test_name">Test</option>
一直在尋找對谷歌的答案,但無法找到一個!
[HTML選項元素(https://developer.mozilla.org/en/docs/Web/HTML/Element/選項)沒有'name'屬性。 – Jamiec