2
11
2009
0

[JavaScript]动态得到select控件选中的值

 

<html>
<head>
<script type="text/javascript">
function getElements(){
    var x=document.getElementsByTagName("select");
    for(var i=0; i<x.length; i++){
        alert(x[i][x[i].selectedIndex].value);
    }
}
</script>
</head>
<body>
<select>
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
</select>
<br />
<select>
<option value=a>a</option>
<option value=b>b</option>
<option value=c>c</option>
</select>
<br />
<input type="button" onclick="getElements()" value="选中了什么?" />
</body>
</html>
 
Category: JavaScript | Tags: javascript 动态表单 | Read Count: 2108

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com