手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >javascript获取select的当前值示例代码(兼容IE/Firefox/Opera/Chrome)
javascript获取select的当前值示例代码(兼容IE/Firefox/Opera/Chrome)
摘要:JavaScript获取Select当前值写法:varvalue=document.getElementById("select").opt...

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>

function check() {

var select = document.getElementById("select").options[document.getElementById("select").options.selectedIndex].value;

alert(select);

}

</script>

<select name="select" id="select">

<option value="test1" selected="selected">Test1</option>

<option value="test2">Test2</option>

</select>

<input type="button" value="我要试试"/>

【javascript获取select的当前值示例代码(兼容IE/Firefox/Opera/Chrome)】相关文章:

javascript结合Flexbox简单实现滑动拼图游戏

javascript下使用Promise封装FileReader

javascript的函数第1/3页

理解javascript定时器中的单线程

Javascript特效:随机显示图片的源代码

Javascript的IE和Firefox兼容性汇编

javascript实现控制的多级下拉菜单

手机开发必备技巧:javascript及CSS功能代码分享

javascript中createElement的两种创建方式

Js和JQuery获取鼠标指针坐标的实现代码分享

精品推荐
分类导航