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. (C#) SQLite数据库连接字符串

    最常用的:Data Source=filename;Version=3; 自增主键: Create  test1( [id] integer PRIMARY KEY AUTOINCREMENT ,[n ...

  2. jenkins maven testng selenium自动化持续集成

    准备环境 首先我们新建一个maven的工程,并且在pom.xml中配置好我们依赖的一些jar包 <dependencies> <dependency> <groupId& ...

  3. 面经:Google两轮背靠背

    如题,谷歌两轮背靠背电面.两轮都是废话不多说直奔coding,虽然第一轮的中国大哥还是花了一点点时间了解了一下我的背景.毕业时间.research方向.说好的research面呢? 中国大哥出的题: ...

  4. mov指令

    一.规定 1.立即数不能作为目的操作数,如mov 110H,AX 2.立即数不能直接传给段寄存器,如mov DS,110H 2.两个操作数不能同时为段寄存器,如mov ES,DS 3.两个操作数不能同 ...

  5. zookeeper 详解

    是 分布式 协调 服务. ZK的工作:注册:所有节点向ZK争抢注册,注册成功会建立一套节点目录树,先注册的节点为Active节点,后注册节点成为standby;监听事件:节点在ZK集群里注册监听动作: ...

  6. Groovy中的闭包

    Closures(闭包) 本节主要讲groovy中的一个核心语法:closurs,也叫闭包.闭包在groovy中是一个处于代码上下文中的开放的,匿名代码块.它可以访问到其外部的变量或方法. 1. 句法 ...

  7. 使用 amcharts 和 highcharts 绘制多曲线时间趋势图的通用方法

    工作中用到, 这里分享一下. 可以使用 amcharts 和 highcharts 在同一坐标中绘制多个对比曲线图. 当然, 对图形没有过多装饰, 可以参考 API 文档: highcharts:   ...

  8. linux常用命令:killall 命令

    killall命令用进程的名字来杀死进程. 1.命令格式:    killall [ -egiqvw ] [ -signal ] [进程名称] 格式:killall -<signame> ...

  9. 20165207 Exp3 免杀原理与实践

    Exp3 免杀原理与实践 1.实验内容 1.1.使用msf 1.1.1. 确定基准线 首先看kali的ip 直接msfvenom的结果,不加其他的东西: 使用VirusTotal得到的检测这个程序得到 ...

  10. seo标题关键字描述字数限制Title,keywords,description长度最长多长 ?

    seo标题关键字描述字数限制 seo优化各个搜索引擎收录Title,keywords,description长度最长多长 ?SEO网站优化中Title标签的作用为重中之重,好的Title也就成功了一半 ...