django编辑框实现

一些常用的:

  • CKEditor
  • UEEditor
  • TinyEditor
  • KindEditor

下载:

http://kindeditor.net/down.php

使用方法:

<textarea name="comment" id="comment"></textarea>
<script>
$(function () {
 initKindEditor();
});
function initKindEditor() {
    var kind = KindEditor.create(
        '#comment', {
            width: '100%' ,
            height: '300px',
           uploadJson:'/uploadimg',
extraFileUploadParams: {
'csrfmiddlewaretoken': '{{ csrf_token }}'
} ) } </script>

  或者:

var editor;
        KindEditor.ready(function (K) {
            editor = K.create('textarea[name="comment"]', {
                resizeType: 1,
                allowPreviewEmoticons: false,
                allowImageUpload: false,
                items: [
                    'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                    'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                    'insertunorderedlist', '|', 'emoticons', 'image', 'link'],
                    uploadJson:'/uploadimg',  #文件上传功能
extraFileUploadParams: {
'csrfmiddlewaretoken': '{{ csrf_token }}'
}); });

后台返回

def uploadimg(request):
    import json
    dic = {
        'error': 0,
        'url': '/static/img/4.jpg',
        'message': '错误了...'
    }

    return HttpResponse(json.dumps(dic))

  

详细参数

http://kindeditor.net/docs/option.html

内容提交

 $('#commentsubmit').click(function () {
     console.log(editor.html())
 })

相关链接:

https://www.cnblogs.com/wupeiqi/p/6307554.html

猜你喜欢

转载自www.cnblogs.com/qiangayz/p/9195577.html