<asp:DropDownList id="DropDownList1" runat="server">
<asp:ListItem Value="1">11111</asp:ListItem>
<asp:ListItem Value="2">222222</asp:ListItem>
</asp:DropDownList>
<div id="div1">11111</div>
<div id="div2">22222</div>
function change()
{
//下面这句使用Form1.DropDownList1.value无法得到value,要用getElementById
if(document.getElementById ('DropDownList1').value=="1")
{
div2.style.display = "none";
div1.style.display = "block";
}
else
{
div2.style.display = "block";
div1.style.display = "none";
}
}
//下面是重点,为DropDownList1控件的onChange事件绑定js的change()函数
private void Page_Load(object sender, System.EventArgs e)
{
DropDownList1.Attributes.Add("onChange", "change();");
}
<asp:ListItem Value="1">11111</asp:ListItem>
<asp:ListItem Value="2">222222</asp:ListItem>
</asp:DropDownList>
<div id="div1">11111</div>
<div id="div2">22222</div>
function change()
{
//下面这句使用Form1.DropDownList1.value无法得到value,要用getElementById
if(document.getElementById ('DropDownList1').value=="1")
{
div2.style.display = "none";
div1.style.display = "block";
}
else
{
div2.style.display = "block";
div1.style.display = "none";
}
}
//下面是重点,为DropDownList1控件的onChange事件绑定js的change()函数
private void Page_Load(object sender, System.EventArgs e)
{
DropDownList1.Attributes.Add("onChange", "change();");
}