this.options[selectedIndex]的使用
生活随笔
收集整理的這篇文章主要介紹了
this.options[selectedIndex]的使用
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
<select id="sel" οnchange="javascript:getSelect();">
<option value="a">選擇</option>
<option value="bdd">be</option>
<option value="c">ce</option>
<option value="d">de</option>
<option value="e">ee</option>
</select>
<script>
function getSelect() {//得到select下拉列表中option的valuevar optionValue = document.getElementById("sel").options[document.getElementById("sel").options.selectedIndex].value;//得到select下拉列表中option的textvar optionText = document.getElementById("sel").options[document.getElementById("sel").options.selectedIndex].text;
}
</script><select id="sele" οnchange="javascript:getE();">
<option value="monday">星期一</option>
<option value="tuesday">星期二</option>
<option value="wednesday">星期三</option>
<option value="thursday">星期四</option>
<option value="friday">星期五</option>
</select>
<script>
function getE() {//我建議這里也像下面一些寫,雖然這樣寫也可以獲得數(shù)據(jù)var optionsValue = document.getElementById("sele").value;alert(optionsValue);var optionsText = document.getElementById("sele").options[document.getElementById("sele").options.selectedIndex].text;alert(optionsText);
}
</script>轉(zhuǎn)載于:https://www.cnblogs.com/moqiang02/p/4061625.html
總結(jié)
以上是生活随笔為你收集整理的this.options[selectedIndex]的使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 9星蛋获得的途径
- 下一篇: 老虎老鼠傻傻分不清楚是什么歌啊?