Simditor 富文本编辑器基本使用

官方文档: https://simditor.tower.im/docs/doc-usage.html

Simditor是一个非常不错的web轻量级编辑器,设置简单,功能较为齐全,重点是样式相对较为好看 ^_^

引入文件

  • css
<link rel="stylesheet" href="plugins/simditor/css/app.css">
<link rel="stylesheet" href="plugins/simditor/css/mobile.css">
<link rel="stylesheet" href="plugins/simditor/css/simditor.css">
  • js
<script src="plugins/simditor/js/module.js"></script>
<script src="plugins/simditor/js/uploader.js"></script>
<script src="plugins/simditor/js/hotkeys.js"></script>
<script src="plugins/simditor/js/simditor.js"></script>

基本实例化

  • html
<textarea name="comment" id="editor"></textarea>
  • js
var editor = new Simditor({
    toolbar: [
        'title', 'bold', 'italic', 'underline', 'strikethrough', 'fontScale',
        'color', '|', 'ol', 'ul', 'blockquote', 'code', 'table', '|', 'link',
        'image', 'hr', '|', 'alignment'
    ],
    textarea: '#editor',
    placeholder: '写点什么...',
    defaultImage: '/static/home/images/logo.png',
    imageButton: ['upload'],
    upload: {
        url: '/article/upload',
        params: {_token: token},
        fileKey: 'file',
        leaveConfirm: '正在上传文件..',
        connectionCount: 3
    }
});

常用方法

  • 设置值: editor.getValue()
  • 获取值: editor.setValue(value)
  • 获取焦点: editor.focus()
  • 失去焦点: editor.blur()

常用参数

  • 编辑器实例化textarea节点,可以是jqueyr选择器也可以是jquery对象: textarea
  • 图片上传方式按钮: imageButton
  • 上传图片相关参数(object): upload
  • 上传地址: upload.url
  • 上传附加参数(object): upload.params
  • 上传的name值: fileKey: 'file' 在服务端接收的键(以PHP为例): $_FILE['file']

注意点

  • 上传文件时,必须返回一个指定格式的 json, 不然报错
echo json_encode([
    'success' => true,
    'msg' => '图片上传错误信息',
    'file_path' => '/upload/2018_10_11/1.jpg'
]);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值