单击时切换按钮的文本 Jquery

Toggle text of a button on click Jquery

我想使用 jquery 在点击时切换按钮的文本,但它无法正常工作。

<asp:Button ID="btnedit" runat="server" Text="Edit" Visible="True"
                    CssClass="actButton" CausesValidation="False" OnClick="btnedit_Click" />

在客户端:

$("#<%= btnedit.ClientID %>").click(function (e) {    
    $(this).text(function (i, text) {
        return text === "Edit" ? "Cancel" : "Edit";
    });
});

有人可以告诉我如何解决这个问题吗?

我觉得你的选择器不正确

 $("#<%= btnedit.ClientID %>")

应该是

 $("#btnedit")

我解决了你的问题,你可以试试这个。

JSFiddle demo

请尝试使用 val()

$("#btnedit").click(function (e) {    
    $(this).val("Edit" ? "Cancel" : "Edit");
});