获取所选选项的内部html [英] Get inner html of the selected option
本文介绍了获取所选选项的内部html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的东西:
select = document.getElementById("select");
select.onchange = function(){
alert(this.value); //returns the selected value
alert(this.innerHTML); //returns the entire select with all the options
alert(this.selected.innerHTML); //this is what I want, but doesn't work, of course
};
如何在纯js中获取所选选项的innerHTML? (没有框架)。
How can I get the innerHTML of the selected option in pure js? (no frameworks).
推荐答案
尝试:
alert(this.options[this.selectedIndex].text);
演示:
<select onchange="alert(this.options[this.selectedIndex].text)">
<option>foo
<option>bar
<option>foobar
</select>
这篇关于获取所选选项的内部html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文