表单已在开头隐藏。当我选择Window时,表单应该可见,但它不会。我尝试添加一个if-else语句,如果没有匹配则会显示警告,但这也不起作用。我猜它永远不会开火。有谁知道为什么?
以下是代码:
<asp:Content ID="Content2" ContentPlaceHolderID="HeaderContent" Runat="Server">
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
function DropDownlistOptions() {
var dropdownlist = document.getElementById("DropDownListForm");
var selected = dropdownlist.options[dropdownlist.selectedIndex].value;
if (selected == "Window") {
document.getElementById("WindowForm").style.visibility = "visible";
}
else {
alert("failed");
}
}
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="Content1" Runat="Server">
<asp:DropDownList ID="DropDownListForm" runat="server" onchange="DropDownlistOptions()">
<asp:ListItem Selected="True">Please Select</asp:ListItem>
<asp:ListItem>Window</asp:ListItem>
<asp:ListItem>Linux</asp:ListItem>
</asp:DropDownList>
<div id="WindowForm" style="visibility:hidden;">
Form info to fill.....
</div>
</asp:Content>
答案 0 :(得分:0)
我找到了解决方案,我只需要添加
document.getElementById("<%=DropDownListForm.ClientID%>");