当我只有硬编码选项时,如何提取选项文本(选择)?
<select ng-change="addLanguage( )" ng-model="language">
<option value=af>Afrikaans</option>
...
(374563 options more)
...
</select>
那么我怎样才能得到&#34;南非荷兰语&#34;在我的addLanguage()
?请注意,html中的选项很难,没有json。
答案 0 :(得分:1)
为您的选择标记添加ID:
<select id="taal" ng-change="addLanguage( )" ng-model="language">
<option value=af>Afrikaans</option>
...
(374563 options more)
...
</select>
然后它会真的很容易:
var elem = document.getElementById("taal");
var taal = elem.options[elem.selectedIndex].text;
答案 1 :(得分:1)
你可以这样做:
<select id="languageSelect" ng-change="addLanguage( )" ng-model="language">
<option value=af>Afrikaans</option>
...
(374563 options more)
...
</select>
<script>
function addLanguage()
{
window.alert(document.getElementById("languageSelect").options[document.getElementById("languageSelect").selectedIndex].innerHTML); //this will have text in it
}
</script>