将Javascript更改为更新面板
我有JavaScript,工作非常出色,但我需要将其更改为更新面板,我无法让它仍然正常工作 我想要它做的是,如果它在第一个下拉列表中选择1,在第二个下拉列表中选择c 我正在使用asp.NETVB。我感谢所有的帮助将Javascript更改为更新面板,javascript,asp.net,vb.net,updatepanel,Javascript,Asp.net,Vb.net,Updatepanel,我有JavaScript,工作非常出色,但我需要将其更改为更新面板,我无法让它仍然正常工作 我想要它做的是,如果它在第一个下拉列表中选择1,在第二个下拉列表中选择c 我正在使用asp.NETVB。我感谢所有的帮助 <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascr
<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>
函数编号DropDownList_OnChange(){
var numbersDropDownList=document.getElementById(“numbersDropDownList”);
if(numbersDropDownList.options[numbersDropDownList.selectedIndex].text==“1”){
document.getElementById(“lettersDropDownList”)。选择的索引=2;
}
}
1.
2.
3.
A.
B
C
希望这有帮助
<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.
2.
3.
A.
B
C
受保护的子编号DropDownList\u SelectedIndexChanged(ByVal sender作为对象,ByVal e作为System.EventArgs)处理编号DropDownList.SelectedIndexChanged
如果NumberDropDownList.selectedvalue=2,则
lettersDropDownList.selectedvalue=3
如果结束
端接头
看起来您从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>
函数编号DropDownList_OnChange(){
var numbersDropDownList=document.getElementById(“”);
if(numbersDropDownList.options[numbersDropDownList.selectedIndex].text==“1”){
document.getElementById(“”)。selectedIndex=2;
}
}
您想用updatepanel包装哪个控件?howHearWhere.ascx谢谢!好吧,上面显示的代码中没有使用该控件…当我将其添加到控件时,Javascript停止工作,所以我只是粘贴了正在工作的内容。对不起,我对这一切都很陌生,所以如果你能提供帮助,并且你需要我提供更多信息,请让我知道。