<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function getOption(){
//获取option的值
var node = document.getElementById("city");
var children = node.options;
for(var i=0;i<children.length;i++){
alert(children[i].value);
}
}
//获取选中的值
function getOptionCurentValue(){
var node = document.getElementById("city");
var children = node.options;
var selectIndex = node.selectedIndex;
alert(children[selectIndex].value);
}
</script>
</head>
<body>
<select id="city" οnchange="getOptionCurentValue()">
<option>北京</option>
<option>上海</option>
<option>武汉</option>
<option>杭州</option>
</select>
<input type="button" value="点击" οnclick="getOption()" />
</body>
</html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript">
function getOption(){
//获取option的值
var node = document.getElementById("city");
var children = node.options;
for(var i=0;i<children.length;i++){
alert(children[i].value);
}
}
//获取选中的值
function getOptionCurentValue(){
var node = document.getElementById("city");
var children = node.options;
var selectIndex = node.selectedIndex;
alert(children[selectIndex].value);
}
</script>
</head>
<body>
<select id="city" οnchange="getOptionCurentValue()">
<option>北京</option>
<option>上海</option>
<option>武汉</option>
<option>杭州</option>
</select>
<input type="button" value="点击" οnclick="getOption()" />
</body>
</html>