簡體   English   中英

獲取JavaScript中組合框的選定索引的值

[英]get value of selected index of combo box in javascript

我正在嘗試獲取我的JavaScript中所選索引的值

在這里,我正在定義我的列表框

<select name="combo" id="combo"  OnBlur="retrieveData(this.form)" ></select>

在這里,我試圖獲取價值(在表格內)

    alert(form.combo.value); // NOT working
    alert(form.combo.selectedIndex)  // working
    alert(form.combo.selectedIndex.value)  // NOT working

但顯示“未定義”

form.combo.options[form.combo.selectedIndex].value;

試試這個:在你的HTML:

<select name="combo" id="combo" OnBlur="getComboVal(this)" ></select>

在javascript中:

function getComboVal(sel)
{
    alert (sel.options[sel.selectedIndex].value);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM