kindeditor 編輯器php
博客園用的 TinyMCE 編輯器 支持拖放/粘貼上傳圖片css
下載 KindEditor 最新版本,下載以後打開 examples/index.html 就能夠看到演示。html
下載頁面: http://www.kindsoft.net/down.phpjson
解壓 kindeditor-x.x.x.zip 文件,將全部文件上傳到您的網站程序目錄裏,例如:http://您的域名/editor/瀏覽器
Note服務器
您能夠根據需求刪除如下目錄後上傳到服務器。asp.net
<textarea id="editor_id" name="content" style="width:700px;height:300px;"> <strong>HTML內容</strong> </textarea>
Notejsp
<script charset="utf-8" src="/editor/kindeditor.js"></script> <script charset="utf-8" src="/editor/lang/zh-CN.js"></script> <script> KindEditor.ready(function(K) { window.editor = K.create('#editor_id'); }); </script>
Note編輯器
var options = { cssPath : '/css/index.css', filterMode : true }; var editor = K.create('textarea[name="content"]', options);
// 取得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內容');
Note函數
// 關閉過濾模式,保留全部標籤
KindEditor.options.filterMode = false; KindEditor.ready(function(K)) { K.create('#editor_id'); }
調節參數參考 http://kindeditor.net/doc.php
例如:
KindEditor.ready(function(K)) { K.create('#editor_id',{
width:"800",
heigth:"600",
.....
}
); }
編輯器上傳文件
指定上傳文件的服務器端程序。
上傳圖片、Flash、視音頻、文件時,支持添加別的參數一併傳到服務器。
KindEditor.ready(function(K) { K.create('#id', { extraFileUploadParams : { item_id : 1000, category_id : 1 } }); });
Note
4.1.1版本開始支持。
上傳文件寫法
KindEditor.ready(function(K)) { K.create('#editor_id',{
uploadJson:「/upload/」, #上傳文件儲存路徑
extraFileUploadParams : {
csrfmiddlewaretoken:$("[name='csrfmiddlewaretoken']").val()
},
filePostName:"upload_img" #知道上傳文件的key值
}
def upload(request):
"""
編輯器上傳文件接受視圖函數
:param request:
:return:
"""
print(request.FILES)
img_obj=request.FILES.get("upload_img") #取出文件對象
print(img_obj.name)
path=os.path.join(settings.MEDIA_ROOT,"add_article_img",img_obj.name) #文件保存路徑
with open(path,"wb") as f:
for line in img_obj:
f.write(line)
import jsonresponse = { 'error':0, 'url':'media/add_articel_img%s'%img_obj}# 返回圖片路徑,預覽圖片return HttpResponse(json.dumps(response))