【问题标题】:Disable linkbutton (anchor tag) with jquery使用 jquery 禁用链接按钮(锚标记)
【发布时间】:2013-03-31 23:37:54
【问题描述】:

我的 jquery 在第一次点击后无法点击链接按钮时遇到问题。

点击还应该删除并添加一些 cssStyles。

问题不在于链接按钮(以 html 呈现的锚标记)在 cssStyles 更改后被禁用。

回发后(由我手动触发)它会被禁用。但这不是我想要的。我希望它是一个顺利的交易,没有回发。

标记代码:

<asp:LinkButton ID="LinkButton" runat="server" OnClientClick="" CommandName="Answer" CssClass="linkButton" >
   <asp:Panel ID="PoptionText" runat="server" CssClass="buttonStyle">
      <%# Eval("optionText") %>
      <div>
         <asp:Label ID="lbRätt" runat="server" Visible="false" CssClass="aktiv"></asp:Label>
      </div>
   </asp:Panel>
</asp:LinkButton>

Javascript 代码:

$(document).ready(function () {
    $("#LinkButton").click(function () {    
        $("#LinkButton").attr("disabled", "disabled"); //this does not happen
        Rightanswer(); // This happens. Function to add remove cssStyles
    })
    $("#LinkButton").click(function (e) {
        if ($("#LinkButton").attr("disabled") == "disabled") {
            e.preventDefault();
        }
    });    
});

【问题讨论】:

    标签: jquery linkbutton javascript


    【解决方案1】:

    您不能将disabled 属性与锚标记一起使用,只有input 元素具有disabled 属性。您可以尝试类似

    $("#LinkButton").click(function (e) {
         if ($("#LinkButton").hasClass(className)) {
            // If have class dont follow href so will work only for first time 
            e.preventDefault();
         }
         Rightanswer(); // Add / Remove class
    });      
    

    这可能有助于Should the HTML Anchor Tag Honor the Disabled Attribute?

    【讨论】:

      【解决方案2】:

      你也可以试试这个:

      $("#<%=LinkButton.ClientID %>").click(function (e) {
         e.preventDefault();
         $(this).attr("disabled", "disabled");
         // Whateverr your code goes here
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-02-01
        • 2021-05-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多