zoukankan      html  css  js  c++  java
  • KindEditor:Ajax提交表单时获取不到HTML内容

    当用Ajax提交表单时,KindEditor的内容获取不到,HTML数据获取不了

    原因:当ajax提交时,KindEdito的HTML数据还没有同步到表单中来,那怎么去获取HTML数据呢?

    ---------------------------------------------------

    KindEditor 4.x documentation:获取HTML数据

    // 取得HTML内容
    html = editor.html();

    // 同步数据后可以直接取得textarea的value
    editor.sync();
    html = document.getElementById('editor_id').value; // 原生API
    html = K('#editor_id').val(); // KindEditor Node API
    html = $('#editor_id').val(); // jQuery

    // 设置HTML内容
    editor.html('HTML内容');

    ----------------------------------------------------

    从这可看出,当Ajax提交表单时,textarea的value还是空的,需要使用sync()去同步HTML数据

    那么在什么时候去同步,怎么同步?KindEditor同时提供了方法:

    afterBlur

    编辑器失去焦点(blur)时执行的回调函数。

    数据类型: Function
    默认值: 无

    最后答案和解决办法:

        <script type="text/javascript">
            KindEditor.ready(function (K) {
                window.editor = K.create('#AContent', {
                    afterBlur: function () { this.sync(); }
                });
            });
        </script>
  • 相关阅读:
    娿
    我不知道啊
    Android怎么把引入的library库工程转换成jar包
    高斯消元入门和简单应用
    数论函数基本知识
    AC自动机入门和简单应用
    FFT和NTT
    同余系基本知识
    虚树学习笔记
    Windows常用快捷键和基本的Dos命令
  • 原文地址:https://www.cnblogs.com/yuejin/p/3747331.html
Copyright © 2011-2022 走看看