javascript bootstrap Summernote 重置/清除

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29420038/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 10:30:35  来源:igfitidea点击:

bootstrap Summernote reset/clear

javascriptjquerytwitter-bootstrap-3wysiwygsummernote

提问by maxlk

I would like to know how to reset or clear the bootstrap Summernote WYSIWYG editor using jQuery or JavaScript.

我想知道如何使用 jQuery 或 JavaScript 重置或清除引导程序 Summernote WYSIWYG 编辑器。

I tried below codes

我试过下面的代码

$('#MyForm').delay(1000).resetForm(1000);

This dose reset the whole form except for the textarea with the Summernote

此剂量重置整个表单,除了带有 Summernote 的 textarea

$('#SummernoteText').reset();

SummernoteText is the html textarea but the code doesn't do anything at all.

SummernoteText 是 html textarea 但代码根本不做任何事情。

$('#SummernoteText').destroy();

Above seems to distroy the editor instead of clearing the editor.

以上似乎破坏了编辑器而不是清除编辑器。

Can someone point me out the way to do this.

有人可以指出我的方法来做到这一点。

Link to Summernote http://summernote.org/#/

链接到 Summernote http://summernote.org/#/

采纳答案by Sanya

$('#SummernoteText').code('');

回答by naribo

A little late, but just to add:

有点晚了,但只是补充一下:



Option 1:

选项1:

$('#SummernoteText').summernote('reset');

This solution will only work if your editor was initially empty

此解决方案仅在您的编辑器最初为空时才有效

This will reset your editor to its original state. Meaning, if you initialized it with any data, the same data will re-appear on reset.

这会将您的编辑器重置为其原始状态。这意味着,如果您使用任何数据对其进行初始化,则相同的数据将在重置时重新出现。



Option 2:

选项 2:

$('#SummernoteText').summernote('code', '<p><br></p>');

The reason for adding the <p><br></p>tags instead of just plain ''is that summernote editing area needs it for focus. (Reference)

添加<p><br></p>标签而不是简单的原因''是summernote编辑区域需要​​它作为焦点。(参考)

回答by Mr world wide

For Summernote 0.8.1 version use this simple code:

对于 Summernote 0.8.1 版本,请使用以下简单代码:

$("#SummernoteText").summernote("reset");

回答by Raheel Hasan

You can build a custom button into the toolbar of the editor itself like this:

您可以在编辑器本身的工具栏中构建一个自定义按钮,如下所示:

//first create the button
var clearAllButton = function (context)
{
    var ui = $.summernote.ui;

    // create button
    var button = ui.button({
        contents: '<b>x</b>',
        tooltip: 'Clear All',
        click: function()
        {
            $("#summernote_field").summernote('code', '');
            $("#summernote_field").summernote({focus: true});
        }
    });

    return button.render();
};

//now set the options to include it
$('#summernote_field').summernote({
    toolbar: [
    .
    .
    .
    .
    ['misc', ['clearAll']]
    ],

    buttons: {
        clearAll: clearAllButton
    },

});