首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > JavaScript >

怎么取得下拉列表的文本

2012-02-28 
如何取得下拉列表的文本functionpl(){varcatanamedocument.all.cata1.options[this.selectedIndex].inner

如何取得下拉列表的文本
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

热点排行