summernote - 如何在summernote中更改输入行为

标签 summernote

我有这个旧代码

// myenter.js, enter key is binded to insertParagraph command.
    $.summernote.addPlugin({
      name : 'myenter',
      events : {
        // redefine insertParagraph 
        'insertParagraph' : function(event, editor, layoutInfo) {
      //you can use summernote enter 
      //layoutInfo.holder().summernote('insertParagraph');   

      // also you can use your enter key 
      layoutInfo.holder().summernote('insertNode', document.createTextNode("\r\n")); 

     // to stop enter key 
     //e.preventDefault();
    }
  }
});

$('.summernote').summernote({ height : 300 });

但现在添加插件的方法已经改变,我希望通过此代码使用新版本的此功能

$.extend($.summernote.plugins, {
    'myenter': function (context) {
        console.log('myenter');
    }
});

但它根本没有被调用

我曾尝试通过以下方式获得相同的功能 summernote.onEntersummernote.keyPress 但它给出了错误..

最佳答案

$.extend($.summernote.plugins, {
    'brenter': function (context) {
        this.events = {
            'summernote.enter': function (we, e) {
                // insert 2 br tags (if only one br tag is inserted the cursor won't go to the next line)
                document.execCommand('insertHTML', false, '<br><br>');
                e.preventDefault();
            }
        };
    }
}

关于summernote - 如何在summernote中更改输入行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37567346/

相关文章:

javascript - 在javascript中获取文本选择中的当前节点

javascript - summernote 编辑器未打开(laravel 5.2)

c# - 是否可以从 ASP.NET Web 表单中的 Summernote 编辑器获取值(value)?

javascript - 在 summer note JS 中加载数据时弹出意外标识符错误

javascript - 更改 summernote div 时 Textarea 值更改

javascript - 在 Summernote 中设置文本区域的背景颜色?

javascript - SummerNote ContentEditable 属性 Make False

bootstrap-4 - Summernote 样式不起作用

python - 名称错误 : name 'static_url' is not defined

javascript - 在 Summernote 上传的图像之间插入 br 标签