2
這段JavaScript代碼有什麼問題。我想在asp.net中顯示和隱藏下拉列表的Div On Change()。但這是行不通的。問題是div顯示但立即隱藏。在asp.net中使用DropDownList顯示和隱藏Div
<script type = "text/javascript">
function ToggleVisible(ddl) {
var div1 = document.getElementById('div_zam ');
var div2 = document.getElementById('div_mah');
var value = ddl.options[ddl.selectedIndex].value;
if (value == 2) {
div1.style.display = "none";
div2.style.display = "block";
}
else {
div1.style.display = "block";
div2.style.display = "none";
}
}
</script>
<asp:DropDownList ID="myddl" runat="server" OnChange="ToggleVisible(this)"
Width="127px" CssClass="style7" style="font-size: medium" Height="30px"
Font-Names="B Nazanin" ValidationGroup="3" AutoPostBack="True"
>
<asp:ListItem Value="0">select</asp:ListItem>
<asp:ListItem Value="1">one</asp:ListItem>
<asp:ListItem Value="2">two</asp:ListItem>
</asp:DropDownList>