【问题标题】:jQuery Summernote - Get text back into editorjQuery Summernote - 将文本返回到编辑器
【发布时间】:2014-03-30 20:59:01
【问题描述】:

我在将文本恢复到 Summernote 编辑器时遇到问题。

我已经尝试过(但没有成功):

$("#EDITsummernote").innerHtml = 'test';

怎么做?

【问题讨论】:

  • 试试这个 $("#editsummernote").text("teset");
  • 您好,谢谢您的回答。是 $("#editsummernote").code("teset");

标签: jquery


【解决方案1】:

自 v0.7.0 code() 已被弃用和删除(destroy() 方法的情况相同)。

你必须使用$(".summernote").summernote("code", "your text");

参考:https://summernote.org/getting-started/#get--set-code

在 v0.7.0 之后,直接 jquery 方法,destroycode 被删除以避免与其他 jquery 库冲突。您可以使用 Summernote api 调用此方法。

【讨论】:

  • 这实际上似乎在旧版本中创建了 Summernote 编辑器的新实例...
  • 没错。如果您已经有初始化功能,那么您仍然可以使用.summernote('code', contentVariable);
  • @ChristopherMilne 不,如果你的summernote以某种方式重新启动(在我的情况下,我原来的高度),这实际上是因为你的summernote(“code”)函数在你原来的启动之前运行代码(也许你把你的summernote(“代码”)函数放在另一个函数中,并在你原来的启动代码之前不小心调用了它)
【解决方案2】:
$(".summernote").code("your text");

【讨论】:

  • 请简要说明您的代码做了什么以及为什么建议这样做。
  • @MathieuCastets 您应该添加更新的解决方案作为单独的答案,而不是编辑这篇文章。然后,您可以在此答案中编辑它已过时。请参阅有关 Meta 的讨论:meta.stackoverflow.com/questions/265433/…
  • @GeraldSchneider 谢谢你的建议
  • 试试这个:$('#summernote').summernote ('code', '<b> hello world </ b>');
【解决方案3】:

插入文字:

$('#summernote').summernote('editor.insertText', 'hello world');

如果你想在编辑器中设置(粘贴)HTML代码,你可以使用这一行:

$('#summernote').summernote('editor.pasteHTML', '<b>hello world</b>');

Source code

奖金

清除所有编辑器内容:

$('#summernote').code("");

【讨论】:

  • 清除内容并删除所有存储的历史记录,使用这个:$('#summernote').summernote('reset'); 以下是文档:summernote.org/deep-dive/#reset
【解决方案4】:

设置:

$('#summernote').summernote('code', '<b> hello world </b>');

获得:

var get_code = $('#summernote').summernote('code');

文档:http://summernote.org/getting-started/#get--set-code

【讨论】:

    【解决方案5】:

    在summernote编辑器中设置文本:

    $('#summernote').summernote('editor.insertText', 'hello world');
    

    【讨论】:

    • 不适用于' hello world ',要工作,看我的回答。
    • 您的代码还有 1 个括号。请删除它。
    【解决方案6】:

    在我这样做之前,没有任何解决方案对我有用。

    &lt;textarea name="description" class="form-control summernote_rpt summernote_custom"&gt;&lt;/textarea&gt;

    假设您已经初始化了类似这样的 Summernote,其中我有两个类 使用了.summernote_custom $('.summernote_rpt').summernote(options);

    当整个页面加载时,当我想使用我使用的 js 更新 Summernote 值时 $('.summernote_rpt').summernote('code','data');

    【讨论】:

      猜你喜欢
      • 2018-07-06
      • 2017-01-10
      • 2014-09-07
      • 2015-06-14
      • 2016-11-02
      • 2016-02-02
      • 2015-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多