我有2个下拉列表dl9和dl10,如下所示。
如果我从dl9 dl10中单击“是”,就会显示它,否则就会隐藏它。
现在,当我单击'no‘并将其转到数据库时,我希望为dl10设置选定的'none’值;如果是的话,‘已完成’和‘正在进行’必须使b变得可见。
我该怎么做?
<asp:DropDownList ID="DropDownList9" runat="server" Width="128px" onchange="display()" >
<asp:ListItem Value="yes">Yes</asp:ListItem>
<asp:ListItem Value="no">No</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList10" runat="server" Width="107px" TargetControlID="DropDownList9" >
<asp:ListItem Value="completed">Completed</asp:ListItem>
<asp:ListItem Value="ongoing">Ongoing</asp:ListItem>
<asp:ListItem Selected="True" Value="none" Enabled="False">[SELECT]</asp:ListItem>
</asp:DropDownList>我隐藏dl10的Javascript是:
<script type="text/javascript" language="javascript">
function display()
{
if (document.getElementById('<%=DropDownList9.ClientID%>').value == "no")
{
document.getElementById('d1').style.visibility = "hidden";
document.getElementById('<%=DropDownList10.ClientID%>').style.visibility = "hidden";
document.getElementById('<%=DropDownList10.ClientID%>').value = "none";
//DropDownList10.SelectedValue = "none"; not wrkin
}
else {
document.getElementById('<%=DropDownList10.ClientID%>').style.visibility = "visible";
document.getElementById('d1').style.visibility = "visible";
}
}
</script>我的问题是:当我点击“否”并提交“已完成”进入database....but时,我需要输入“无”.
发布于 2013-09-06 06:55:30
Enabled="False"属性在ListItem中造成问题。
<asp:ListItem Selected="True" Value="none" Enabled="False">[SELECT]</asp:ListItem>我拆掉了,检查了一下,一切都很好。
更新
如果要隐藏该选项,则在javaScript加载页面时隐藏该选项。在script标记中编写这段代码,它将隐藏该选项。
window.onload = function () {
document.getElementById('<%=DropDownList10.ClientID%>').options[2].style.display = "none";
};/Update
https://stackoverflow.com/questions/18651343
复制相似问题