富文本编辑器 summernote.js
1、引用js 可在 https://summernote.org/ 官网下载 ,并查看详细的API 引入:summernote.js 和 summernote-zh-CN.js 以及样式文件:summernote.css
2、Html
<textarea class="summernote" data-type="w"></textarea>
3、初始化summernote
/**
* 初始化富文本框 summernote
* */
function initSummernote() {
$('.summernote').summernote({
lang: 'zh-CN',
height: 300,
placeholder: "详情...",
minHeight: null, // set minimum height of editor
maxHeight: null, // set maximum height of editor
focus: false,
disableDragAndDrop: true,
dialogsInBody: true,
dialogsFade: true,
fontSizes: ['8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25'],
fontNames: [
'Arial', 'Arial Black', 'Comic Sans MS', 'Courier New',
'Helvetica Neue', 'Helvetica', 'Impact', 'Lucida Grande',
'Tahoma', 'Times New Roman', 'Verdana', 'Microsoft YaHei'
],
toolbar: [
// [groupName, [list of button]]
['style', ['bold', 'italic', 'underline', 'clear', 'fontsize', 'fontname']],
['color', ['color']],
['font', ['style', 'strikethrough', 'superscript', 'subscript', 'height']],
//['para', ['ul', 'ol', 'paragraph']],
['para', ['paragraph']],
//['video', ['video']],
['picture', ['picture']],
['link', ['link']],
['table', ['table']],
//['hr', ['hr']],
['undo', ['undo']],
['redo', ['redo']],
['help', ['help']],
['codeview', ['codeview']]
],
callbacks: {
//上传回调
onImageUpload: function (files) { //the onImageUpload API
var type = $(this).data('type');
$.each(files, function (i, item) {
sendFile(item, type);
});
},
//删除回调
onMediaDelete: function (target) {
deleteFile(target);
}
}
});
//解决选择图片时 打开本地文件夹时,有延时问题。
$('.note-image-input').prop('accept', 'image/jpeg, image/jpg, image/png, image/gif');
}
/**
* Summernote 上传图片到服务器
* @param {any} file 图片文件
* @param {string} type 图片类型,在textarea 标签 中 添加 data-type 属性 英文 小写
*/
function sendFile(file, type) {
data = new FormData();
data.append("file", file);//根据实际情况传参
data.append("dir", type);
$.ajax({
data: data,
type: "POST",
url: "/",
cache: false,
contentType: false,
processData: false,
success: function (result) {
if (result.success) {
$(".summernote").summernote('insertImage', result.url);
} // the insertImage API
},
error: function () {
alert('上传失败!');
}
});
}
/**
* Summernote 删除到服务器中的图片
* @param {object} target//回调参数
*/ function deleteFile(target) {
var picUrl = target.attr('src');
$.ajax({
data: { },
type: "POST",
url: "/",
processData: true,
success: function (result) {
},
error: function () {
alert('删除失败!');
}
}); }
4、使用:直接调用
initSummernote()就可以完成初始化。
富文本编辑器 summernote.js的更多相关文章
- 超好用的富文本编辑器Summernote的使用
官网地址 中文文档 源码下载地址 Summernote依赖于jquery和bootstrap3/4 所以用时记得引入这俩依赖 奉上引入方法(官网说的很清楚,api也很详细): <!-- in ...
- 富文本编辑器summerNote
载入富文本: $('.summernote').summernote({ height: 220, tabsize: 2, lang: 'zh-CN' }); 富文本获取内容: $('.summern ...
- 富文本编辑器summernote的基本使用
summernote比较突出的优点就是能保持复制过来的东西的原有样式,并且比较流畅. 官方文档地址:https://summernote.org/getting-started 我是用到cdn引入 & ...
- 富文本编辑器 wangEditor.js
1.引用 wangEditor 相关js 和 css 下载地址:https://files.cnblogs.com/files/kitty-blog/WangEditor.zip 3.页面: < ...
- SummerNote 富文本编辑器 - Rails 集成
使用官方提供的CDN服务 将下面一段加入layout文件中 <link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/css ...
- bbs项目引入富文本编辑器和处理xss攻击和文章预览
一.富文本编辑上传文章和图片 富文本编辑器我们使用kindeditor,我们首先去官网下载,然后解压,放到我们的static的目录中 然后我们在html中这样使用富文本编辑器 <!DOCTYPE ...
- 使用wangEditor富文本编辑器
客户端配置说明 下载 百度网盘地址:点我下载 下载密码:x09x 使用 首先要引入wangEditor的js文件,然后引入jQuery 然后在body里: <body> <butto ...
- summernote富文本编辑器
下载summernote官方demo,解压,把文件夹中的summernote.js,summernote.css和font整个文件夹都放到服务器对应的项目目录里 引入summernote 所需要的bo ...
- summernote富文本编辑器的使用
最近在开发一个微信公众号的后台,微信公众号编辑的文章一直没有得到很好地适应,大多数人也是在其他的编辑软件中编辑好之后直接去复制到微信公众平台中,考虑到复制后会排版出现问题,所以给大家推荐一款很不错的W ...
随机推荐
- BZOJ2438: [中山市选2011]杀人游戏(tarjan)
题意 题目链接 Sol 这题挺考验阅读理解能力的.. 如果能读懂的话,不难发现这就是在统计有多少入度为\(0\)的点 缩点后判断一下即可 当然有一种例外情况是\(1 -> 3, 2 -> ...
- js for in 遍历对象与数组
遍历对象 let obj = { q:'9', w:'5', e:'2', t:'7', c:'3' } //for in 遍历对象 key为对象的属性名称,遍历属性值时用[]操作符访问 //通过[] ...
- 【转】SNR , Eb/N0 , Es/N0区别与联系
原文地址:http://www.360doc.com/content/16/0505/23/532901_556620735.shtml 通信方向在做仿真时经常用到信噪比这个参数,而对于不同形式的信号 ...
- Android使用Fragment来实现TabHost的功能
http://www.cnblogs.com/tiantianbyconan/p/3360938.html 好了,到此为止,我们已经用Fragment实现了类似TabHost的功能了,下面来看下各个F ...
- Java中long和Long有什么区别(转)
Java的数据类型分两种:1.基本类型:long,int,byte,float,double,char2. 对象类型(类): Long,Integer,Byte,Float,Double,Char,S ...
- Visual Studio 快捷键汇总
常见方法: 强迫智能感知:Ctrl+J.智能感知是Visual Studio最大的亮点之一,选择Visual Studio恐怕不会没有这个原因. 撤销:Ctrl+Z.除非你是天才,那么这个快捷键也是 ...
- MySQL 5.7 修改数据物理文件目录
修改MySQL数据库物理文件存放位置,需要在MySQL配置文件中修改相关参数.安装MySQL5.7后,在MySQL安装目录下没有找到数据库物理文件,最后经过查找发现其在“C:\ProgramData\ ...
- t d x 示例z
using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServi ...
- nodejs理解
一.nodejs介绍 nodejs主要体现在事件机制和异步IO,nodejs是事件驱动的: nodejs作用:js的运行环境.操作文件.链接数据库: nodejs在执行js是单线程的,但不是nodej ...
- json 二进制传输方案
json 传输二进制数组方案 json 是一种很简洁的协议,但可惜的是,它只能传递基本的数型(int,long,string等),但不能传递byte类型.如果想要传输图片等二进制文件的话,是没办法直接 ...