Can't Enable button in JavaScript

2020-04-21 02:47发布

问题:

<script type="text/javascript"> 
   function Enable_Butt() {               
         document.getElementById("<%=RadButton1.ClientID%>").disabled = false; // Doesn't Work                                                      
   }
</script>

i also tried this and still not work //$find("<%=RadButton1.ClientID %>").set_enabled(true);

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
  <ContentTemplate>
    <telerik:RadButton ID="RadButton1" runat="server"  SingleClick="true" SingleClickText="Processing..." AutoPostBack="true" OnClick="Create_Order_Click" Text="Create Order" Font-Bold="true" Font-Size="12" BackColor="#333333" ForeColor="White" Skin="Bootstrap" CssClass="auto-style5"  >
    </telerik:RadButton>
    <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="5000" ></asp:Timer>
  </ContentTemplate>
  <Triggers>
    <asp:AsyncPostBackTrigger ControlID="RadButton8" EventName="Click" />
    <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
   </Triggers>
</asp:UpdatePanel>


protected void Timer1_Tick(object sender, EventArgs e){
     ScriptManager.RegisterStartupScript(Page, Page.GetType(), " ", "Enable_Butt()", true);
}

回答1:

Instead of setting the disabled attribute to false, just remove it:

function Enable_Butt() {
  document.getElementById("button").removeAttribute("disabled");
}

 document.getElementById("b").addEventListener("click", Enable_Butt)
<button disabled id="button">Button</button>
<button id="b">Enable</button>