Home >Web Front-end >JS Tutorial >Javascript gets the current value of select sample code (compatible with IE/Firefox/Opera/Chrome)_javascript skills

Javascript gets the current value of select sample code (compatible with IE/Firefox/Opera/Chrome)_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:08:47948browse

JavaScript获取Select当前值写法:
var value = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;
var text = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].text;

例子:

复制代码 代码如下:

<script><br>function check() {<br>      var select = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;<br>      alert(select);<br>}<br></script>



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn