html:
<form action="">
<p>選擇城市</p>
<p>
<select name="" id="cont">
<option value="北京" order="1">北京</option>
<option value="上海" order="2">上海</option>
<option value="廣州" order="3">廣州</option>
</select>
</p>
<p>
<input type="button" value="ok" id="btn"/>
</p>
</form>
js:
//方法一:取出想要的選項內容
var btn=document.getElementById("btn");
var cont=document.getElementById("cont");
btn.onclick=function(){
//alert(cont.value);
};
//方法二:取出想要的內容
btn.onclick=function(){
//先得到選擇的索引值
var index=cont.selectedIndex;
//把option選項放到一個數組里
var arr=cont.options;
//從數組中取出某個索引的值
var text=arr[index].value;
var order=arr[index].getAttribute("order");
alert(order);
};
