【问题标题】:add event to summernote when code view activated激活代码视图时向summernote添加事件
【发布时间】:2019-01-28 00:56:49
【问题描述】:

如何在激活代码视图时向summernote添加事件?

我想在输入代码时触发按键操作。我正在尝试,但效果不佳。

$(document).ready(function(){
    $('#summernote').on('summernote.init', function () {
        $('#summernote').summernote('codeview.activate');
    }).summernote({
        height: 300,
        toolbar: [],
        codemirror: {
            theme: 'monokai'
        }
    });

    $('#summernote').on('summernote.keyup', function(we, e) {
        console.log('Key is released:', e.keyCode);
    });
});

【问题讨论】:

    标签: jquery summernote


    【解决方案1】:

    您可以使用 Summernote 网站上所述的以下解决方案:

    $('#summernote').summernote({
      callbacks: {
        onKeyup: function(e) {
          setTimeout(function(){
            console.log('Key is released:', e.keyCode);
          },200);
        }
     }
    });
    

    还有很多其他的回调事件可以在这里找到,包括初始化事件:https://summernote.org/deep-dive/

    //You need to call summernote and add the callback then add your summernote.init event
    
    $('#summernote').summernote({
      callbacks: {
        onInit: function() {
       console.log('Summernote is launched');
    }
    }
    });
    

    【讨论】:

    • 这是正确的,但是当我添加 onInit 来初始化summernote时它不起作用
    • @carrow 我的答案已修改。您是否在控制台中看到有关您的 init 事件的任何错误?
    • 你用的是什么版本的summernote和jquery?
    猜你喜欢
    • 2013-08-16
    • 2011-02-11
    • 2015-04-20
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多