Code
$(function(){
$('#<%=ddlType.ClientID%>').change(function(){
if($(this).val()=='2')
$('#<%=panel1.ClientID%>').show();
else
$('#<%=panel1.ClientID%>').hide();
});
})
偷懒下
jquery的实现方式
<script type="text/javascript">
function change(obj){
if(obj.value=="3"){
document.getElementById("Panel1").style.display="block";
}else{
document.getElementById("Panel1").style.display="none";
}
}
</script>
然后给你的DropDownList加一个onchange="change(this)";
<script type="text/javascript">
function change(obj){
var aa=obj.options[obj.selectedIndex].value;
if(aa=="3"){
document.getElementById("Panel1").style.display="block";
}else{
document.getElementById("Panel1").style.display="none";
}
}
</script>
把你dropdownlist中的AutoPostBack去掉,把Panel 中的 Visible="false" 改成 style="display:none;"
就可以了
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="aa.aspx.cs" Inherits="text2_aa" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
function change(obj){
var aa=obj.options[obj.selectedIndex].value;
if(aa=="3"){
document.getElementById("Panel1").style.display="block";
}else{
document.getElementById("Panel1").style.display="none";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlType" runat="server" size="1" onclick="change(this)" OnSelectedIndexChanged="ddlType_SelectedIndexChanged"
>
<asp:ListItem Value="0" Selected="True">请选择</asp:ListItem>
<asp:ListItem Value="1">公告</asp:ListItem>
<asp:ListItem Value="2">动态</asp:ListItem>
<asp:ListItem Value="3">优惠信息</asp:ListItem>
</asp:DropDownList>
<asp:Panel ID="Panel1" runat="server" style="display:none;" >
<tr>
<td class="style1">
优惠时间
</td>
<td>
<asp:TextBox ID="txtStarttime" runat="server" size="10" CssClass="Wdate" onFocus="new WdatePicker(this,'%Y-%M-%D',true,'default')"></asp:TextBox>
——
<asp:TextBox ID="txtEndttime" runat="server" size="10" CssClass="Wdate" onFocus="new WdatePicker(this,'%Y-%M-%D',true,'default')"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="*" ForeColor="#FF3300"></asp:Label>
</td>
</tr>
</asp:Panel>
</div>
</form>
</body>
</html>