Select选中项
方法一:
html源码:
<select name="select" onchange="changeSelectB()">
<option value="aaa">1</option>
<option value="bbb">2</option>
<option value="ccc">3</option>
<option value="ddd">4</option>
</select>
js源码:
function changeSelectB() {
//取得选中项的值或者编号,不传this时候写法
var select = document.getElementById("select");
var vA = select.options[select.selectedIndex].value;
var vB = select.options[select.selectedIndex].text;
alert(vA);
alert(vB);
}
方法二:
html源码:
<select name="select" onchange="changSelect(this)">
<option value="aaa">1</option>
<option value="bbb">2</option>
<option value="ccc">3</option>
<option value="ddd">4</option>
</select>
js源码:
function changSelect(choose) {
//取得选中项的值或者编号,传this时候写法
var aa = choose.options[choose.selectedIndex].text;
var bb = choose.options[choose.selectedIndex].value;
alert(aa);
alert(bb);
}