SummerNote wysiwyg编辑器保存在codeview不工作js/jquery

SummerNote wysiwyg编辑器保存在codeview不工作js/jquery

问题描述:

我使用Summernote作为wysiwyg编辑器,但我有一个问题。我的大部分文本编辑都是在代码视图中进行的,问题是如果您在代码视图中提交表单,编辑的文本不会保存。SummerNote wysiwyg编辑器保存在codeview不工作js/jquery

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

我已经看到这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'); 
    } 
} 
+0

它似乎不适合我。问题是如果我尝试加载表单上的任何东西,它会返回true,无论我做什么。 –

+1

尝试使用它。 ('#desc')。summernote('codeview.isActivated')){ $('#desc')。summernote('codeview.deactivate'); } –

+0

此解决方案的工作原理! –