3 回答

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
如果你有一個(gè)如下所示的select元素:
<select id="ddlViewBy">
<option value="1">test1</option>
<option value="2" selected="selected">test2</option>
<option value="3">test3</option>
</select>
運(yùn)行此代碼:
var e = document.getElementById("ddlViewBy");
var strUser = e.options[e.selectedIndex].value;
會(huì)strUser成為2。如果你真正想要的是test2,那么這樣做:
var e = document.getElementById("ddlViewBy");
var strUser = e.options[e.selectedIndex].text;
哪個(gè)會(huì)strUser成為test2

TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個(gè)贊
var strUser = e.options[e.selectedIndex].value;
這是正確的,應(yīng)該給你價(jià)值。這是你要追求的文字嗎?
var strUser = e.options[e.selectedIndex].text;
所以你對(duì)術(shù)語(yǔ)很清楚:
<select> <option value="hello">Hello World</option></select>
此選項(xiàng)包括:
指數(shù)= 0
值=你好
Text = Hello World
添加回答
舉報(bào)