网页前端设计

http://www.86y.org

搜索文章

js获取select值(兼容火狐、IE浏览器)

用声音读出全文关注我吧
 2014/1/4 16:14:05 阅读次数:7304

本文介绍下,用js获取select中值的方法,可以兼容火狐firefox与IE浏览器,代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js获取select值(兼容火狐、IE浏览器)www.86y.org</title>
</head>

<body>
<SELECT name="games" id="games" style="width:143px" onchange="chooseGeme()">
   <option value="1">test1</option>  
   <option value="2">test2</option>
   <option value="3">test3</option>
   <option value="4">test4</option>
   <option value="5">test5 </option>
   <option value="6">test6</option>  
</SELECT>
<script>
/**
* 取得select中的值
* edit www.86y.org
*/
function chooseGeme(){
  var games =document.getElementById("games");
  var gameoid = games.options[games.selectedIndex].value;
  alert(gameoid)
 }
</script>
</body>
</html>

(完)


大家有什么问题或技术上的想法可以在此与大家分享,也可以加入前端爱好者QQ群(141999928)一起学习进步:【幸凡前端技术交流群】
0

如果您觉得本文的内容对您的学习有所帮助,捐赠与共勉,支付宝(左)或微信(右)

阅读全文内容关闭