Javascript 获取javascript中组合框选定索引的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8098799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 04:43:47 来源:igfitidea点击:
get value of selected index of combo box in javascript
提问by junaidp
i am trying to get the value of the selected index in my javascript
我正在尝试在我的 javascript 中获取所选索引的值
here i am defining my list box
在这里,我正在定义我的列表框
<select name="combo" id="combo" OnBlur="retrieveData(this.form)" ></select>
here i am trying to get the value (inside the form)
在这里,我正在尝试获取值(在表单内)
alert(form.combo.value); // NOT working
alert(form.combo.selectedIndex) // working
alert(form.combo.selectedIndex.value) // NOT working
but its showing "undefined"
但它显示“未定义”
回答by Niet the Dark Absol
form.combo.options[form.combo.selectedIndex].value;
回答by rogerlsmith
try this: in your html:
试试这个:在你的html中:
<select name="combo" id="combo" OnBlur="getComboVal(this)" ></select>
in javascript:
在 JavaScript 中:
function getComboVal(sel)
{
alert (sel.options[sel.selectedIndex].value);
}