js怎么返回option自定义属性的值?

来源:百度知道 编辑:UC知道 时间:2024/05/13 19:30:47
<select id="catid">
<option value="9" text="on">A P B A</option>
<option value="10" text="on">新闻动态</option>
<option value="11" text="on">人物专访</option>
<option value="12" text="on">行进管乐</option>
<option value="13" text="off">名作赏析</option>
<option value="14" text="on">管乐知识</option>
<option value="15" text="off">关闭评论</option>
</select>

如何获取text值?用
document.getElementById('catid')[0].text只能获取指定的option值,但我不知道用户会选择第几个option啊

var obj=document.getElementById("catid");
var index=obj.selectedIndex;
var text=obj.options[index].getAttribute("text");
//上面过程就是把select >> option >> text 值取出来
alert('text = ' + text);
return text;