function Select_Changed() {
var temp = document.all('DropDownList1').options[document.all('DropDownList1').selectedIndex].text;
switch(temp)
{
case "GroupA":
document.all("DropDownList2").options.length = 0;
var tOption = document.createElement("Option");
tOption.text= "a";
tOption.value=document.all("DropDownList2").options.length+1;
document.all("DropDownList2").add(tOption);
var tOption = document.createElement("Option");
tOption.text= "b";
tOption.value=document.all("DropDownList2").options.length+1;
document.all("DropDownList2").add(tOption);
break;
default:
break;
}
}
</script>
<asp:DropDownList id="Dropdownlist1" onchange="Select_Changed()" runat="server" >
<asp:ListItem Value="GroupA">GroupA</asp:ListItem>
<asp:ListItem Value="GroupB">GroupB</asp:ListItem>
<asp:ListItem Value="GroupC">GroupC</asp:ListItem>
<asp:ListItem Value="GroupD">GroupD</asp:ListItem>
</asp:DropDownList>
本文介绍了一种使用JavaScript在客户端动态更新下拉列表的方法,无需与服务器进行交互。通过监听下拉菜单的选择变化,根据选择项的不同动态生成新的选项。
164

被折叠的 条评论
为什么被折叠?



