Html 如何从html中的列表框中获取值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17628356/
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-29 11:04:27  来源:igfitidea点击:

how to get value from list box in html

htmllistbox

提问by Angripa

This is an example,

这是一个例子,

<select>
    <option value=1>Cars</option>
</select>

How i can get the value of selected "1" and value in list box "Cars"?

如何在列表框“汽车”中获取所选“1”的值和值?

回答by Vijay

try out this

试试这个

<select id="selectID">
    <option value=1>Cars</option>
</select>

using javascript

使用 JavaScript

var e = document.getElementById("selectID");
var strUser = e.options[e.selectedIndex].value;

回答by Jay Shukla

jQuery("#sltbox").find("option[value=1]").attr("selected","selected")

Give id as sltbox to your select tag.

将 id 作为 sltbox 提供给您的选择标签。