Check selected item in <select>-Roll?

2019-08-26 23:18发布

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

1条回答
啃猪蹄的小仙女
2楼-- · 2019-08-27 00:06

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>
查看更多
登录 后发表回答