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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM