請允許我嗶嗶兩句,真是難受啊,有問題去百度,結果百了一堆亂七八糟的內容,有頭沒尾,有尾沒頭的,搞得我暈頭轉向,現在把kindeditor獲取HTML的終極打法無償分享出來,這可是我配置查找了一下午的成果。先把代碼貼出來,文件引入看自己的文件位置。
<script> KindEditor.ready(function(K) {
//大概是初始化的意思吧 editor = K.create('textarea[name="content1"]', { uploadJson: 'upload_json.php', fileManagerJson: 'file_manager_json.php', allowFileManager: true, afterCreate: function() { var self = this; K.ctrl(document, 13, function() { self.sync(); K('form[name=example]')[0].submit(); }); K.ctrl(self.edit.doc, 13, function() { self.sync(); K('form[name=example]')[0].submit(); }); } }); prettyPrint(); }); </script> <script> function btn() {
點擊時獲取獲取html editor.sync(); html = document.getElementById('con').value; //原生API console.log(html); } </script>
這是主要的javascript。現在也把完整的代碼放出來,如果幫到你,記得留下個腳印

<?php $htmlData = ''; if (!empty($_POST['content1'])) { if (get_magic_quotes_gpc()) { $htmlData = stripslashes($_POST['content1']); } else { $htmlData = htmlspecialchars($_POST['content1']); } } ?> <!doctype html> <html> <head> <meta charset="utf-8" /> <title>KindEditor PHP</title> <link rel="stylesheet" href="../themes/default/default.css" /> <link rel="stylesheet" href="../plugins/code/prettify.css" /> <script src="../kindeditor-all-min.js"></script> <script src="../lang/zh-CN.js"></script> <script src="../plugins/code/prettify.js"></script> <script> KindEditor.ready(function(K) { editor = K.create('textarea[name="content1"]', { uploadJson: 'upload_json.php', fileManagerJson: 'file_manager_json.php', allowFileManager: true, afterCreate: function() { var self = this; K.ctrl(document, 13, function() { self.sync(); K('form[name=example]')[0].submit(); }); K.ctrl(self.edit.doc, 13, function() { self.sync(); K('form[name=example]')[0].submit(); }); } }); prettyPrint(); }); </script> <script> function btn() { editor.sync(); html = document.getElementById('con').value; //原生API console.log(html); } </script> </head> <body> <?php echo $htmlData; ?> <form name="example" method="post" action="demo.php"> <textarea id="con" name="content1" style="width:700px;height:200px;visibility:hidden;"><?php echo htmlspecialchars($htmlData); ?></textarea> <br /> <input type="submit" name="button" value="提交內容" /> (提交快捷鍵: Ctrl + Enter) </form> <button onclick="btn()">獲取html?</button> </body> </html>