jQuery Summernote - 将文本恢复到编辑器中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22068379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Summernote - Get text back into editor
提问by cr1zz
I got problems getting text back into the summernote editor.
我在将文本返回到 Summernote 编辑器时遇到了问题。
I already tried (but did not work):
我已经尝试过(但没有用):
$("#EDITsummernote").innerHtml = 'test';
How to do that?
怎么做?
回答by Mathieu Castets
Since v0.7.0code()
has been deprecated and removed (same story for destroy()
method).
由于 v0.7.0code()
已被弃用和删除(destroy()
方法相同)。
You must use $(".summernote").summernote("code", "your text");
你必须使用 $(".summernote").summernote("code", "your text");
Reference: https://summernote.org/getting-started/#get--set-code
参考:https: //summernote.org/getting-started/#get--set-code
After v0.7.0, direct jquery methods,
destroy
andcode
were removed for avoiding conflict with other jquery libraries. You can call this methods with summernote api.
v0.7.0之后,直接jQuery方法,
destroy
并且code
是为避免与其他的jQuery库冲突删除。您可以使用 summernote api 调用此方法。
回答by Mathieu Castets
$(".summernote").code("your text");
$(".summernote").code("your text");
回答by Abel
Insert Text:
插入文本:
$('#summernote').summernote('editor.insertText', 'hello world');
You can use this line if you want to set (paste) HTML code in editor:
如果要在编辑器中设置(粘贴)HTML 代码,可以使用此行:
$('#summernote').summernote('editor.pasteHTML', '<b>hello world</b>');
Bonus
奖金
Clear all editor content:
清除所有编辑器内容:
$('#summernote').code("");
回答by Matheus Miranda
To set:
设置:
$('#summernote').summernote('code', '<b> hello world </b>');
To get:
要得到:
var get_code = $('#summernote').summernote('code');
Documentation: http://summernote.org/getting-started/#get--set-code
回答by Abhi Burk
None of the Solutions works for me until I did this.
在我这样做之前,没有一个解决方案对我有用。
<textarea name="description" class="form-control summernote_rpt summernote_custom"></textarea>
<textarea name="description" class="form-control summernote_rpt summernote_custom"></textarea>
Let's say you have initialized summernote something like this in which I have two classes
.summernote_custom
was used
$('.summernote_rpt').summernote(options);
比方说,你有初始化summernote这样的事情中,我有两个类
.summernote_custom
使用
$('.summernote_rpt').summernote(options);
when the entire page loads and when I wanted to update the summernote value using js I used
$('.summernote_rpt').summernote('code','data');
当整个页面加载时以及当我想使用我使用的 js 更新 summernote 值时
$('.summernote_rpt').summernote('code','data');
回答by wander
To set text in the summernote editor:
在 Summernote 编辑器中设置文本:
$('#summernote').summernote('editor.insertText', 'hello world');