例子:
<select id="select">
<option value="A" url="http://www.baidu.com">第一個
option</option>
<option value="B" url="http://www.qq.com">第二個
option</option>
</select>
方法一:JavaScript原生方法
1.拿到select對象:var myselect=document.getElementById("select");
2.拿到選中項的索引:var index =myselect.selectedIndex;//selectedIndex代表的是你所選中項的 index
3.拿到選中項option的value:myselect.option[index].value;
4.拿到選中項option的text:myselect.option[index].text;
5.拿到選中項的其他值,例如其中的url:沒有select.options [index].getAttribute('url');
方法二:jQuery方法
1.var options=$("#select option:selected");//獲取選中的項
2.alert(options.val());//展示選中項的值
3.alert(options.text());//展示選中項的文本
4.alert(options.attr('url'));//展示選中項的url值