脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-基于jquery的bootstrap在线文本编辑器插件Summernote,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。
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 | <scriptsrc="//code.jquery.COM/jquery-1.9.1.min.js"></script><scriptsrc="//netdna.bootstrapcdn.com/bootstrap/3.0.1/js/bootstrap.min.js"></script><scriptsrc="summernote.min.js"></script> |
写入htML,只需加入一个DIV元素,写上ID
1 | HelloSummernote |
写入JS初始化插件
1 2 3 | $(document).ready(function(){ $('#summernote').summernote(); }); |
初始化Summernote
1 | $('.summernote').summernote(); |
使用参数初始化
设定高度与焦点
1 2 3 4 5 6 7 | $('.summernote').summernote({ height:300,//setedITorheight minHeight:null,//setminimumheightofeditor maxHeight:null,//setmaximumheightofeditor focus:true,//setfocustoeditableareaafterinitializingsummernote}); |
设定高度后,如果内容高度超过设定高度将出现滚动条,如果没有设定高度则一直往下挣开。设定focus为true时,打开页面后焦点定位到编辑器中。
自定义工具栏
1 2 3 4 5 6 7 8 9 10 11 12 | $('.summernote').summernote({ toolbar:[ //[groupname,[buttonlist]] ['style',['bold','italic','underline','clear']], ['font',['strikethrough']], ['fontsize',['fontsize']], ['color',['color']], ['para',['ul','ol','paragraph']], ['height',['height']], ] }); |
预设参数
类型
方法 | |
---|---|
picture | Insert a picture |
link | Insert a hyPErlink |
video | Insert a video |
table | Insert a table |
hr | Insert a horizontal rule |
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 |
ul | Make an un-ordered list |
ol | Make an ordered list |
paragraph | Set text alignment |
height | Set height of text |
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').summernote({ airPopover:[ ['color',['color']], ['font',['bold','underline','clear']], ['para',['ul','paragraph']], ['table',['table']], ['insert',['link','picture']] ] }); |
释放Summernote
1 | $('.summernote').destroy(); |
取值与赋值
1 2 3 4 5 6 | //取值 VARsHTML=$('.summernote').code(); //同一页面多个summernote时,取第二个的值 varsHTML=$('.summernote').eq(1).code(); //赋值 $('.summernote').code(sHTML); |
事件
oninit
1 2 3 4 5 | $('#summernote').summernote({ oninit:function(){ console.log('Summernoteislaunched'); } }); |
onenter
1 2 3 4 5 | $('#summernote').summernote({ onenter:function(e){ console.log('Enter/ReturnkeyPressed'); } }); |
onfocus
1 2 3 4 5 | $('#summernote').summernote({ onfocus:function(e){ console.log('Editableareaisfocused'); } }); |
onblur
1 2 3 4 5 | $('#summernote').summernote({ onblur:function(e){ console.log('Editablearealosesfocus'); } }); |
onkeyup
1 2 3 4 5 | $('#summernote').summernote({ onkeyup:function(e){ console.log('Keyisreleased:',e.keyCode); } }); |
onkeydown
1 2 3 4 5 | $('#summernote').summernote({ onkeydown:function(e){ console.log('KeyisPRessed:',e.keyCode); } }); |
onpaste
1 2 3 4 5 | $('#summernote').summernote({ onpaste:function(e){ console.log('Calledeventpaste'); } }); |
onImageUpload
可以重写图片上传句柄
1 2 3 4 5 | $('#summernote').summernote({ onImageUpload:function(files,editor,$editable){ console.log('imageupload:',files,editor,$editable); } }); |
onChange
IE9-10: DOMCharacterDataModified, DOMSuBTreeModified, DOMNodeInserted
Chrome, FF: input
1 2 3 4 5 | $('#summernote').summernote({ onChange:function(contents,$editable){ console.log('onChange:',contents,$editable); } }); |
支持18国语言,使用时引入你需要的语言文件,lang值设为你需要的语言
1 2 3 4 5 6 7 8 | <scriptsrc="lang/summernote-ko-KR.js"></script>$(document).ready(function(){ $('#summernote').summernote({ lang:'ko-KR'//default:'en-US' }); }); |
觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的javascript代码实例教程-基于jquery的bootstrap在线文本编辑器插件Summernote全部内容,希望文章能够帮你解决javascript代码实例教程-基于jquery的bootstrap在线文本编辑器插件Summernote所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。