查找并设置html里的select的当前选项
1<html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
4<title>无标题文档</title>
5<script language=javascript>
6 function btnTest_onclick()
7 {
8 var testOptions=test.options;
9 var i=0;
10 for (i=0;i<testOptions.length;i++)
11 {
12 if(2==test.options[i].value)
13 {
14 test.selectedIndex=i
15 }
16 }
17 }
18</script>
19</head>
20<body>
21<select name=test size=1>
22<option value="1">a</option>
23<option value="2">b</option>
24</select>
25<input type=button name=btnTest onclick="btnTest_onclick()" value="测 试">
26</body>
27</html>
2<head>
3<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
4<title>无标题文档</title>
5<script language=javascript>
6 function btnTest_onclick()
7 {
8 var testOptions=test.options;
9 var i=0;
10 for (i=0;i<testOptions.length;i++)
11 {
12 if(2==test.options[i].value)
13 {
14 test.selectedIndex=i
15 }
16 }
17 }
18</script>
19</head>
20<body>
21<select name=test size=1>
22<option value="1">a</option>
23<option value="2">b</option>
24</select>
25<input type=button name=btnTest onclick="btnTest_onclick()" value="测 试">
26</body>
27</html>
也是朋友问的(只要有人问也许别人还会问,以后就只发链接就OK了)