重点:当在页面插入文本编辑器后,无法用js/jq的方式去将某些值写入到文本编辑器,如:$("textarea").val("111");$("textarea").text("111");。。。
Summernote提供了指定的方式:$("textarea").Summernote().code(‘111‘);这是赋值,取值也可这样:$("textarea").Summernote().code();
Summernote是一个基于jquery的bootstrap超级简单WYSIWYG在线编辑器。Summernote非常的轻量级,大小只有30KB,支持Safari,Chrome,Firefox、Opera、Internet
Explorer 9 +(IE8支持即将到来)。
特点:
世界上最好的WYSIWYG在线编辑器
极易安装
开源
自定义初化选项
支持快捷键
适用于各种后端程序言语
使用方法
使用html5文档
1 2 3 4 |
|
引入核心文件,Summernote需要几个JS库的支持,所以得先引入其它库
1 2 3 4 5 6 7 8 9 |
|
写入html,只需加入一个DIV元素,写上ID
1 |
|
写入JS初始化插件
1 2 3 |
|
API
初始化Summernote
1 |
|
使用参数初始化
设定高度与焦点
1 2 3 4 5 6 7 |
|
设定高度后,如果内容高度超过设定高度将出现滚动条,如果没有设定高度则一直往下挣开。设定focus为true时,打开页面后焦点定位到编辑器中。
自定义工具栏
1 2 3 4 5 6 7 8 9 10 11 12 |
|
预设参数
类型 | 按钮id | 方法 |
---|---|---|
Insert | picture | Insert a picture |
link | Insert a hyperlink | |
video | Insert a video | |
table | Insert a table | |
hr | Insert a horizontal rule | |
Style | style | Format selected block |
fontname | Set font family | |
fontsize | Set font size | |
color | Set foreground and background color | |
bold | Toggle weight | |
italic | Toggle italic | |
underline | Toggle underline | |
strikethrough | Toggle strikethrough | |
clear | Clearing all styles | |
Layout | ul | Make an un-ordered list |
ol | Make an ordered list | |
paragraph | Set text alignment | |
height | Set height of text | |
Misc | fullscreen | Toggle fullscreen editing mode |
codeview | Toggle wysiwyg and html editing mode | |
undo | Undo | |
redo | Redo | |
help | Show help dialog |
极简模式Air-mode
1 2 3 4 5 6 7 8 9 |
|
释放Summernote
1 |
|
取值与赋值
1 2 3 4 5 6 |
|
事件
oninit
1 2 3 4 5 |
|
onenter
1 2 3 4 5 |
|
onfocus
1 2 3 4 5 |
|
onblur
1 2 3 4 5 |
|
onkeyup
1 2 3 4 5 |
|
onkeydown
1 2 3 4 5 |
|
onpaste
1 2 3 4 5 |
|
onImageUpload
可以重写图片上传句柄
1 2 3 4 5 |
|
onChange
IE9-10: DOMCharacterDataModified, DOMSubtreeModified, DOMNodeInserted
Chrome, FF: input
1 2 3 4 5 |
|
支持18国语言,使用时引入你需要的语言文件,lang值设为你需要的语言
1 2 3 4 5 6 7 8 |
|
版权声明:本文为博主原创文章,未经博主允许不得转载。