select单选

 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
 5     <title>select</title>
 6     <script type="text/javascript" src="eventutil.js"></script>
 7 </head>
 8 <body>
 9     <select name="location" id="selLocation">
10         <option value="0">请选择...</option>
11         <option value="Sunnyvalue, CA">Sunnyvalue</option>
12         <option value="Los Angeles, CA">Los Angeles</option>
13         <option value="Mountain View, CA">Mountaion View</option>
14         <option value="">China</option>
15         <option>Australia</option>
16     </select>
17     <script type="text/javascript" src="test04.js"></script>
18 </body>
19 </html>
1 var selectbox = document.getElementById("selLocation");
2 EventUtil.addHandler(selectbox, "change", function() {
3     var selectedIndex = selectbox.selectedIndex;
4     var selectedOption = selectbox.options[selectedIndex];
5     console.log("Selected index: " + selectedIndex + "\nSelected text: " + selectedOption.text + "\nSelected value: " + selectedOption.value);
6 });
原文地址:https://www.cnblogs.com/qzsonline/p/2534936.html