1.引入

<script type="text/javascript" src="/plugin/ckeditor5/ckeditor.js"></script>

2.html

<div class="form-group col-lg-12">
<label class="control-label col-lg-3 text-right"><span class="control-label required-mark"></span>内容:</label>
<textarea class="form-control-erbi col-lg-5" name="editor" id="editor" /></textarea>
</div>

3.样式

<style>
.ck-editor__main{
width:75%;
padding-right: 0;
float: right;
} .ck-editor__editable {
min-height: 200px;
}
</style>

4.启动

var myEditor = null;
window.onload = function(){
ClassicEditor
.create(document.querySelector("#editor"), {
ckfinder: {
uploadUrl: '/admin.php/Common/ck_editor?command=QuickUpload&type=Files&responseType=json'
}
})
.then(editor => {
myEditor = editor;
// 设置初始值
myEditor.setData('');
})
.catch(error => {
console.error(error);
});
}

5.图片上传后台,文件名默认为upload

public function ck_editor(){
$config = array(
"savePath" => "./site_upload/ck_editor/" , //存储文件夹
"maxSize" => 1000000 , //允许的文件最大尺寸,单位KB
"allowFiles" => array( ".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp" ) //允许的文件格式
); $up = new Uploader( "upload" , $config );
$info = $up->getFileInfo();
$info['url'] = substr($info['url'],1);
$host_name = Func::getHostName();
$url = 'http://' . $host_name . $info['url'];
$qiniu = new QiniuImg();
$ext = pathinfo($url, PATHINFO_EXTENSION);
$name = time() . mt_rand() . '.' . $ext;
$s = $qiniu->up($url, $name, config('app.qiniu.bucket'));
if($s){
@unlink('.'.$info['url']);
$info['url'] = config('cdn_host').$name;
}
if ($info) {
$this->json->setAttr('uploaded',true);
$this->json->setAttr('url',[$info['url']]);
$this->json->Send();
} else {
$this->json->setAttr('uploaded',false);
$this->json->setErr(10099,'上传失败');
$this->json->Send();
}
}

6.获取内容

var htmlStr=myEditor.getData();
$('#editor').val(htmlStr);

配置自己的tarbar

var myEditor = null;
window.onload = function(){
ClassicEditor
.create(document.querySelector("#editor"), {
toolbar: ["undo", "redo", "|", "alignment", "bold", "italic", "blockQuote", "imageTextAlternative", "imageUpload", "heading", "link", "numberedList", "bulletedList"],
ckfinder: {
uploadUrl: '/admin.php/Common/ck_editor?command=QuickUpload&type=Files&responseType=json'
}
})
.then(editor => {
myEditor = editor;
// 设置初始值
myEditor.setData('');
})
.catch(error => {
console.error(error);
});
}

CKEditor5 基本使用的更多相关文章

  1. CKEditor5 + ckfinder3(php)

    CKEditor5资源下载,这里我们选择ckeditor5-build-classic下载: https://ckeditor.com/ckeditor-5-builds/download/ ckfi ...

  2. CKEditor5 + vue2.0 自定义图片上传、highlight、字体等用法

    因业务需求,要在 vue2.0 的项目里使用富文本编辑器,经过调研多个编辑器,CKEditor5 支持 vue,遂采用.因 CKEditor5 文档比较少,此处记录下引用和一些基本用法. CKEdit ...

  3. ckeditor5 安装高亮,颜色插件

    ckeditor5 安装高亮插件 1.准备 git clone -b stable https://github.com/ckeditor/ckeditor5-build-classic.git cd ...

  4. ckeditor5 增加居中alignment

    https://ckeditor.com/docs/ckeditor5/latest/builds/guides/integration/installing-plugins.html 克隆下来 gi ...

  5. ckeditor5富文本编辑器在vue中的使用

    安装依赖: npm install --save @ckeditor/ckeditor5-vue @ckeditor/ckeditor5-build-classic 要创建编辑器实例,必须首先将编辑器 ...

  6. CKEditor5 使用第二天 获取回传数据,图片上传

    1.当系统中存在编辑功能时,需要将数据库中数据回显到页面,因此采用了最一般的方法,通过隐藏的input标签存贮,在通过CkEditor5中的setData方法将数据赋值到富文本框中 <texta ...

  7. CKEditor5 输入文字时拼音和汉字同时输入问题

    在使用 CKEditor5 + vue 时,出现输入文字时,拼音和文字一起输入到编辑器到问题.与之前项目中使用 ckeditor 的区别是,这次项目是在 python 架构下局部引入 ckeditor ...

  8. Ckeditor5显示css样式

    Ckeditor5在编辑模式是通过js加载样式的,但是在显示时没有提供,官方提供了两种方式来实现. https://ckeditor.com/docs/ckeditor5/latest/builds/ ...

  9. ckeditor5字体颜色,字体背景颜色设置显示

    在config.js中添加相关代码: config.allowedContent=true;//关闭标签过滤, config.colorButton_enableAutomatic = true; c ...

随机推荐

  1. 两个list对应元素相加

    a=[1,2,3] b=[4,5,6] 现将list a与 list b按位相加,其结果为[5,7,9] 方法一: c=[a[i]+b[i] for i in range(min(len(a),len ...

  2. Java jdbc 操作数据库详解

    原文地址https://www.cnblogs.com/huguodong/p/5910859.html JDBC(Java Data Base Connectivity,java数据库连接)是一种用 ...

  3. MySQL从删库到跑路_高级(四)——存储过程

    作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.存储过程简介 1.存储过程简介 存储过程是一组具有特定功能的SQl语句集组成的可编程的函数,经编译创建并保存在数 ...

  4. 【Redis学习之九】Redis集群:Twemproxy和HA

    环境 虚拟机:VMware 10 Linux版本:CentOS-6.5-x86_64 客户端:Xshell4 FTP:Xftp4 jdk8 redis-3.0.4 主从模式对写压力没有分担,解决思路就 ...

  5. RocketMQ 集群搭建--双Master方案

    安装环境 jdk1.7 alibaba-rocketmq-3.2.6.tar.gz VM虚拟机redhat6.5-x64:192.168.1.201  192.168.1.202 Xshell4 部署 ...

  6. Jtester+unitils+testng:DAO单元测试文件模板自动生成

    定位 本文适合于不愿意手工编写而想自动化生成DAO单元测试的筒鞋.成果是不能照搬的,但其中的"创建模板.填充内容.自动生成"思想是可以复用的.读完本文,可以了解 Python 读取 ...

  7. Oracle查询session连接数和inactive以及 概要文件IDLE_TIME限制用户最大空闲连接时间

    -----############oracle会话和进程################----------------查询会话总数select count(*) from v$session;--查 ...

  8. ELK学习笔记之Logstash和Filebeat解析对java异常堆栈下多行日志配置支持

    0x00 概述 logstash官方最新文档.假设有几十台服务器,每台服务器要监控系统日志syslog.tomcat日志.nginx日志.mysql日志等等,监控OOM.内存低下进程被kill.ngi ...

  9. 详解 HTML5 中的 WebSocket 及实例代码-做弹幕

    原文链接:http://www.php.cn/html5-tutorial-363345.html

  10. 20145322 Exp5 利用nmap扫描

    20145322 Exp5 利用nmap扫描 实验过程 使用命令创建一个msf所需的数据库 service postgresql start msfdb start 使用命令msfconsole开启m ...