【问题标题】:How to add class to table in froala editor?如何在 froala 编辑器中向表中添加类?
【发布时间】:2016-11-16 21:22:11
【问题描述】:

如何在 froala 编辑器中添加一些 css 类?我需要它,因为我在表上使用了一些引导类,我想从编辑器将它们添加到表中。

我需要添加这个:class="table table-striped table-hover responsive"

感谢您的帮助。

编辑:http://i.imgur.com/Ie0SQ0N.png

你会看到代码的不同:

1) 这就是我现在得到的:<table>

2) 这就是我需要的:

<table class="table table-striped table-hover responsive">

【问题讨论】:

  • 请解释清楚
  • 已编辑;我希望现在很清楚

标签: editor froala


【解决方案1】:

我刚刚意识到我可以在保存到数据库之前使用函数 str_replace。我将使用此解决方案:

function repairTables($text){
    return str_replace('<table width="100%">', '<table class="table table-striped table-hover responsive">', $text);
}

【讨论】:

    【解决方案2】:

    使用 Jquery,您还可以像这样添加类:

    $('div#froala-editor table').addClass('table table-bordered');
    

    如果您想在插入表格时添加它,可以覆盖默认的 Froala 行为:

    $.FroalaEditor.RegisterCommand('tableInsert', {
    callback: function (cmd, rows, cols) {
      this.table.insert(rows, cols);
      this.popups.hide('table.insert');
      $('div#froala-editor table').addClass('table table-bordered');
    }
    

    });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-06-26
      • 1970-01-01
      • 1970-01-01
      • 2019-01-23
      • 1970-01-01
      • 2020-12-14
      • 2019-04-21
      相关资源
      最近更新 更多