繁体   English   中英

Summernote 所见即所得编辑器保存在代码视图中不工作 js/jquery

[英]Summernote wysiwyg editor save in codeview not working js/jquery

我使用Summernote作为所见即所得的编辑器,但我有一个问题。 我的大部分文本编辑都在代码视图中进行,问题是如果您在代码视图中提交表单,则编辑后的文本不会被保存。

出于某种原因,我需要在代码视图和所见即所得视图之间切换以保存编辑的文本。 任何人都有关于如何解决这个问题的任何线索?

在代码视图中看到过Not save content ? #127但它对我不起作用。

这是我的代码。

$(document).ready(function() {
    $('#desc').summernote({
        height: 1000,                 // set editor height
        minHeight: null,             // set minimum height of editor
        maxHeight: null,             // set maximum height of editor
        focus: true,                  // set focus to editable area after initializing summernote
        codemirror: {
          mode: 'text/html',
          htmlMode: true,
          lineNumbers: true,
          theme: 'monokai'
        },
        callbacks: {
          onBlur: function() {
            //should probably do something here
          },
          onInit: function() {
            console.log('Summernote is launched');
            $(this).summernote('codeview.activate');
          }
        }
    });
});

如果需要,这里是 html。

<textarea name="desc" id="desc" class="form-control" rows="40"></textarea>

尝试做这样的事情。

$(document).on("submit","#my-form-name",function(e){
    $("#desc").val($('#desc').code());
    return true;
});

$(document).on("submit","#my-form-name",function(e){
    if ($('#desc').summernote('codeview.isActivated')) {
        $('#desc').summernote('codeview.deactivate'); 
    }
});

这将summernote的代码值复制到文本的值中

$(#desc).on('summernote.blur.codeview', function() {
    $(#desc).val($(desc).summernote('code'));
});

看起来使用 onblur 回调也可以工作: https : //summernote.org/deep-dive/#initialization-options

   $($('.summernote').closest("form")).on("submit",function(e){
        if ($('.summernote').summernote('codeview.isActivated')) {
            $(".summernote").val($('.summernote').summernote());
            return true;
        }
        return true;
    });

    $($('.summernote').closest("form")).on("submit",function(e){
        if ($('.summernote').summernote('codeview.isActivated')) {
            $('.summernote').summernote('codeview.deactivate'); 
        }
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM