可以通过select的onchange()事件去做。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
[url]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/url]">
<html xmlns=" [url]http://www.w3.org/1999/xhtml[/url]">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>
<body>
<select name="test" οnchange="a();" id="test11">
<option value="0">请选择...</option>
<option value="1">第一个</option>
<option value="2">第二个</option>
</select>
<script type="text/javascript">
function a(){
var obj=document.getElementById("test11");
if(obj.options[obj.selectedIndex].value!=0){
window.alert(obj.options[obj.selectedIndex].value);
}
}
</script>
</body>
</html>
<html xmlns=" [url]http://www.w3.org/1999/xhtml[/url]">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled 1</title>
</head>
<body>
<select name="test" οnchange="a();" id="test11">
<option value="0">请选择...</option>
<option value="1">第一个</option>
<option value="2">第二个</option>
</select>
<script type="text/javascript">
function a(){
var obj=document.getElementById("test11");
if(obj.options[obj.selectedIndex].value!=0){
window.alert(obj.options[obj.selectedIndex].value);
}
}
</script>
</body>
</html>
转载于:https://blog.51cto.com/zzjnet/142291