【发布时间】:2022-04-01 15:04:20
【问题描述】:
我有一个简单的代码,它是一个下拉列表和两个按钮(名为启用和禁用)我想通过 javascript 函数启用和禁用下拉列表,然后单击按钮 asp.net HTML 代码:
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
</asp:DropDownList>
<br />
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClientClick="return enable();" Text="enable" />
<asp:Button ID="Button2" runat="server" OnClientClick="return disable2();" Text="disable" />
javascript函数:
function enable() {
document.getElementById("DropDownList1").disabled = false;
document.getElementById("DropDownList2").disabled = false;
return;
}
function disable() {
document.getElementById("DropDownList1").disabled = true;
document.getElementById("DropDownList2").disabled = true;
}
and pageloadlogic:public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
但我尝试了很多次,但没有得到预期的输出,请告诉我解决方案
【问题讨论】:
-
你确定元素的ID吗?编译页面时可以更改它们。要查看它们,请查看浏览器中页面的源代码。
标签: asp.net