选择< select> -Roll中的所选项目? [英] Check selected item in <select>-Roll?

查看:124
本文介绍了选择< select> -Roll中的所选项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我得到一个< select> -Roll与多个项目。如何通过DOM检查哪个项目被选中?我想我通常会知道,但今天整天我都有一个大的停电。

So, I got a <select>-Roll with multiple items. How can I check via DOM which item was selected? I think I'd usually know it but I'm having a big blackout the whole day today...

推荐答案

Javascript:

Javascript:

//Almost any modern browser
document.getElementById("select-element").value;

//for some old browsers
var select = document.getElementById("select-element");
select.options[select.selectedIndex].value;

html:

<select id="select-element">
    <option value="1">1</option>
    <option value="2">2</option>
<select>

这篇关于选择&lt; select&gt; -Roll中的所选项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆