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
Release: 2016-05-16 17:08:47
Original
950 people have browsed it

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>



Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template