【问题标题】:Jquery syntax for .text with html i class [duplicate]带有html i类的.text的Jquery语法[重复]
【发布时间】:2018-09-12 06:21:57
【问题描述】:
function(response) {                    
    if(1 == response) {
        if(type=='favorite'){
            thelink.text('<?php _e('Rem Portfolio', 'sp-favorite-groups'); ?>');
            thelink.addClass('unfavorite-group').removeClass('favorite-group');
        } else {
            thelink.text('<i class="icon-bell"></i><?php _e('Add Portfolio', 'sp-favorite-groups'); ?>');
            thelink.addClass('favorite-group').removeClass('unfavorite-group');
        }
    } else {
        alert(response);
    }
}

我有一个功能/插件可以更改按钮内的文本。如何在文本中包含图标?比如

 thelink.text('<i class="icon-bell"></i><?php _e('Rem Portfolio', 'sp-favorite-groups'); ?>');

显然这不起作用,因为浏览器显示所有 html 标签而不是实际图标。

【问题讨论】:

  • text() 将您提供的内容作为文本节点插入,这就是您看到 html 的原因。如果你想让你给它的东西呈现为标记,你必须使用 html() 或只是 append() 新的标记。
  • 有道理的欢呼

标签: jquery


【解决方案1】:

正如@Taplar 指出的那样,使用 html() 代替;

thelink.html('<i class="icon-bell"></i> Button name');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-20
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 2012-02-23
    • 2014-07-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多