【问题标题】:How to change button text to font awesome icon using jquery如何使用 jquery 将按钮文本更改为字体真棒图标
【发布时间】:2016-07-29 23:10:22
【问题描述】:

我有一个按钮<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。如果我只是输入一些文本,例如“正在连接...”而不是字体真棒,它可以正常工作而不会出现任何错误。

【问题讨论】:

    标签: javascript jquery html font-awesome


    【解决方案1】:

    .html()代替.text()

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

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

        $(".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'));
        });
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-02-28
          • 2022-01-02
          • 1970-01-01
          • 2021-12-10
          • 1970-01-01
          • 2019-06-08
          相关资源
          最近更新 更多