演员许亚军个人资料:关于javascript,怎样对<select>的选项做自定义选择?

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/28 20:34:30
怎样对<select>的选项做自定义选择?想对<select>的选项做动态选择,而不一定是第一项,比如我要选择第4项,
我下面用了两种方法select1都没反应。怎样对<select>的选项做自定义选择?
<html>
<head>
<title></title>
<script language=javascript>
function change()
{
select1.selectedIndex="3";
}
</script>
</head>

<body onload="change();">
<form id="from1" name="from1">
<select id="select1" name="select1">
<option value="1">1111</option>
<option value="2">2222</option>
<option value="3">3333</option>
<option value="4">4444</option>
</select>
<br>
href="#" onclick="change();">change</a>

</form>
</body>
</html>

<script language=javascript>
function change()
{
document.getElementById("select1").selectedIndex="3";
}
</script>
<form id="from1" name="from1">
<select id="select1" name="select1">
<option value="1">1111</option>
<option value="2">2222</option>
<option value="3">3333</option>
<option value="4">4444</option>
</select>
</form>
<a href="javascript:void(0)" onclick="change();">change</a>

<option value="4" selected>4444</option>

有一句话不对:
select1.selectedIndex="3";
应该改成:
document.from1.select1.selectedIndex="3";

全是外文

你 这是写 些什么?我看就 没对的地方!!!!!!!!

这样看是不是你得意思:
<%ss3 = request("s3")%>
<select name="s3" <% If rr1<>3 Then %> disabled=true <% End If %>>
<option value="0" <% If ss3 = 0 Then %>selected <% End If %> >------select-------</option>
<option value="1" <% If ss3 = 1 Then %>selected <% End If %> >Beijing</option>
<option value="2" <% If ss3 = 2 Then %>selected <% End If %>>Guangdong</option>
<option value="3" <% If ss3 = 3 Then %> selected<% End If %>>Hubei</option>
</select>