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

标签 javascript jquery summernote

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

出于某种原因,我需要在代码 View 和所见即所得 View 之间切换以保存编辑的文本。有人知道如何解决这个问题吗?

我看过这个Not saving content while in code view? #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'); 
    }
});

关于javascript - Summernote 所见即所得编辑器保存在代码 View 中不工作 js/jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43745941/

相关文章:

javascript - HTML5 游戏、 Canvas 还是 div?

JavaScript - 我们应该使用 Observables 吗?还是 promise 就足够了?

javascript - 使用 json 的 Highcharts 动态图表

javascript - jQuery + Full Page + Mobile Menu closing =Unable to preventDefault inside passive event listener

javascript - 错误: summernote is not a function when using local files

php - 动态创建div时如何显示/隐藏div

javascript - 检查是否选中了任何单选或复选框

javascript - 为什么 async : false inside a listener, 停止所有执行?

javascript - 在 vue.js 2 中使用 summernote

jquery - 在 summernote 中转义 HTML