继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

kindeditor小使用

慕粉2139185169
关注TA
已关注
手记 30
粉丝 27
获赞 128
kindeditor编辑器
  • 下载kindeditor插件包

    • 提供的php文件夹中有upload_json.php,file_manager_json.php来设置文件上传。
  • 引入js,css文件

    <link rel="stylesheet" href="./k-editor/plugins/code/prettify.css" />
    <script charset="utf-8" src="./k-editor/kindeditor-all.js"></script>
    <script charset="utf-8" src="./k-editor/lang/zh-CN.js"></script>
    <script charset="utf-8" src="./k-editor/plugins/code/prettify.js"></script>
    • html中js写入

      KindEditor.ready(function(K) {
          var editor = K.create('#content', {
              cssPath : './k-editor/plugins/code/prettify.css',
              uploadJson : './k-editor/php/upload_json.php',
              fileManagerJson : './k-editor/php/file_manager_json.php',
              allowFileManager : true,
              newlineTag : 'br',
              afterCreate : function() {
                  this.sync();
      //                  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();
      //                  });
              },
              afterBlur : function(){this.sync();}
          });
          prettyPrint();
      
          editor.html('<?php echo htmlspecialchars_decode($content); ?>');
      
          $('#submit').click(function()
                  {
                      var help_doc_id = $("#help_doc_id").val() ;
                      var title = $("#title").val();
                      var content = editor.html();
                      $.ajax({  
                          type: "POST",  
                          url: "help_and_support_save.php",
                          contentType: "application/json; charset=utf-8",
                          data: JSON.stringify({"help_doc_id":help_doc_id,"title":title,"content":content}),  
                          cache: false,
                          dataType: 'json',
                          success:function(res)
                          {  
                              if( res.code == 0 )
                              {
                                  alert('保存成功!');
                                  window.location.href = 'help_and_support_list.php';
                              }
                              else
                              {
                                  alert('抱歉,保存失败!' + res.data);
                              }
                          }  
                      });  
                  });
      
      });
  • 提交的php页面中获取 content ,然后存入数据库
    $content = htmlspecialchars($content);
打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP