我的JavaScript运行良好,但我需要将其更改为更新面板,我无法让它仍能正常工作。
我想要它做的是如果它在第一个下拉列表中选择1,则在第二个下拉列表中选择c。
我正在使用asp.net vb。我感谢所有的帮助!
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function NumbersDropDownList_OnChange() {
var numbersDropDownList = document.getElementById("numbersDropDownList");
if (numbersDropDownList.options[numbersDropDownList.selectedIndex].text=="1") {
document.getElementById("lettersDropDownList").selectedIndex = 2;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="numbersDropDownList" onchange="NumbersDropDownList_OnChange()" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="lettersDropDownList" runat="server">
<asp:ListItem>a</asp:ListItem>
<asp:ListItem>b</asp:ListItem>
<asp:ListItem>c</asp:ListItem>
</asp:DropDownList>
</div>
</form>
</body>
</html>
答案 0 :(得分:0)
希望这有帮助
<asp:UpdatePanel runat="server" ID="pnllettersDropDownList" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="numbersDropDownList" runat="server" AutoPostBack="true" >
<asp:ListItem Value="1" >1</asp:ListItem>
<asp:ListItem Value="2" >2</asp:ListItem>
<asp:ListItem Value="3" >3</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="lettersDropDownList" runat="server">
<asp:ListItem Value="1" >a</asp:ListItem>
<asp:ListItem Value="2" >b</asp:ListItem>
<asp:ListItem Value="3" >c</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
Protected Sub numbersDropDownList_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles numbersDropDownList.SelectedIndexChanged
if numbersDropDownList.selectedvalue=2 then
lettersDropDownList.selectedvalue=3
end if
End Sub
答案 1 :(得分:0)
看起来你正在通过javascript错误地调用你的控件。您只是因为您的列表位于表单的基本级别而“正常运行”您当前的脚本。
更正您的脚本如下:
<script type="text/javascript">
function NumbersDropDownList_OnChange() {
var numbersDropDownList = document.getElementById('<%= numbersDropDownList.ClientID %>');
if (numbersDropDownList.options[numbersDropDownList.selectedIndex].text=="1") {
document.getElementById('<%= lettersDropDownList.ClientID %>').selectedIndex = 2;
}
}
</script>