开发者

Check selected item in <select>-Roll?

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 开发者_JAVA百科the whole day today...


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜