如何在summernote中更改输入行为

Zoh*_*san 1 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();
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

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

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

$.extend($.summernote.plugins, {
    'myenter': function (context) {
        console.log('myenter');
    }
});
Run Code Online (Sandbox Code Playgroud)

但它根本没有被召唤

我试图通过 它获得相同的功能 summernote.onEnter , summernote.keyPress但它给出了错误..

小智 5

$.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();
            }
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 你能补充一些解释吗? (3认同)