日期:2014-05-16  浏览次数:20396 次

如何取得下拉列表的文本
function   pl()
{

var   cataname=document.all.cata1.options[this.selectedIndex].innerText;
alert(cataname);
}

cata1是个select

如何在下拉cata1时取得该项的文本啊?



------解决方案--------------------
<select id= "cata1 " onchange= "pl(); ">
<option> aaaaaaa </option>
<option> bbbb </option>
<option> cccc </option>
</select>
<script>
function pl(){
var cataname=document.all.cata1.options[document.all.cata1.selectedIndex].text;
alert(cataname);
}
</script>
---------------------
document.all.cata1.options[this.selectedIndex].innerText
中innerText应该用text
另外,如果直接在 <select> 中可以用this,但在函数this指的是函数本身不是 <select> 对象,所以不能用this.
------解决方案--------------------
document.all.cata1.options[document.all.cata1.selectedIndex].text