如何使用 jquery 将按钮文本更改为超赞字体图标

How to change button text to font awesome icon using jquery

我有一个按钮<button class="home-signup-button button-add" formnovalidate>Sign up</button>

单击此按钮后,我想将文本从注册更改为超赞字体图标。 <i class='fa fa-circle-o-notch fa-spin fa-3x fa-fw'></i>。到目前为止我已经试过了

$(".home-signup-button.button-add").click(function(){
    $(this).text("<i class='fa fa-circle-o-notch fa-spin fa-3x fa-fw'></i>");
});

但是我收到一个错误 Uncaught SyntaxError: missing ) after argument list。如果我只是输入一些像 "Connecting..." 这样的文本而不是很棒的字体,它就可以正常工作。

而不是 .text() 使用 .html()

这是我的代码,我会怎么做

$(".home-signup-button.button-add").click(function(){
        $('#change').html("<i class='fa fa-circle-o-notch fa-spin fa-3x fa-fw'></i>");
    });

一种解决方案是执行以下操作:

$(".home-signup-button.button-add").click(function(){
    $(this).html("<i class='fa fa-circle-o-notch fa-spin fa-3x fa-fw'></i>");
});

您也可以这样做:

$(".home-signup-button.button-add").click(function(){
    $(this).append($('i').addClass('fa fa-circle-o-notch fa-spin fa-3x fa-fw'));
});