- K.create(expr [, options])
创建编辑器后可以用 KindEditor.instances 数组取得已创建的所有KEditor对象。
参数:
mixed expr: element或选择器
返回: KEditor
示例:
01// 1
02// editor 等于 KindEditor.instances[0]
03editor = K.create('textarea[name="content"]');
04editor.html('HTML code');
05
06
07// 2
08editor = K.create('#editor_id', {
09 filterMode : true,
10 langType : 'en'
11});
- remove()
参数: 无
返回: KEditor
示例:
1editor.remove();
- html()
参数: 无
返回: string
示例:
1var html = editor.html();
- html(val)
参数:
string val: HTML
返回: KEditor
示例:
1editor.html('<strong>HTML</strong> code');
- fullHtml()
参数: 无
返回: string
示例:
1var fullHtml = editor.fullHtml();
- text()
参数: 无
返回: string
示例:
1var text = editor.text();
- text(val)
参数:
string val: 文本
返回: KEditor
示例:
1editor.text('<strong>HTML</strong> code');
- selectedHtml()
参数: 无
返回: string
示例:
1var html = editor.selectedHtml();
- count([mode])
参数:
string mode: 可选参数,默认值为”html”,mode为”html”时取得字数包含HTML代码,mode为”text”时只包含纯文本、IMG、EMBED。
返回: Int
示例:
1htmlCount = editor.count();
2textCount = editor.count('text');
- isEmpty()
参数: 无
返回: Boolean
示例:
1if (editor.isEmpty()) {
2 alert('请输入内容。');
3}
- insertHtml(val)
参数:
string val: HTML
返回: KEditor
示例:
1editor.insertHtml('<strong>HTML</strong> code');
- appendHtml(val)
参数:
string val: HTML
返回: KEditor
示例:
1editor.appendHtml('<strong>HTML</strong> code');
- focus()
参数: 无
返回: KEditor
示例:
1editor.focus();
- blur()
编辑器失去焦点。
参数: 无
返回: KEditor
示例:
1editor.blur();
- sync()
参数: 无
返回: KEditor
示例:
1editor.sync();
- exec(commandName)
参数:
string commandName: 命令名
返回: KEditor
目前可用的命令:
commandName描述示例bold粗体editor.exec(‘bold’);italic斜体editor.exec(‘italic’);underline下划线editor.exec(‘underline’);strikethrough删除线editor.exec(‘strikethrough’);forecolor文字颜色editor.exec(‘forecolor’, ‘#333’);hilitecolor文字背景editor.exec(‘hilitecolor’, ‘#eee’);fontsize文字大小editor.exec(‘fontsize’, ‘14px’);fontfamily字体editor.exec(‘fontfamily’, ‘SimHei’);fontname字体,fontfamily的别名editor.exec(‘fontname’, ‘SimHei’);removeformat删除inline样式editor.exec(‘removeformat’);inserthtml插入HTMLeditor.exec(‘inserthtml’, ‘<strong>HTML</strong>’);hr插入水平线editor.exec(‘hr’);print弹出打印窗口editor.exec(‘print’);insertimage插入图片editor.exec(‘insertimage’, ‘1.jpg’, ‘title’, 200, 100, 1, ‘right’);createlink超级链接editor.exec(‘createlink’, ‘1.html’, ‘_blank’);unlink取消超级链接editor.exec(‘unlink’);formatblock段落editor.exec(‘formatblock’, ‘<h1>’);selectall全选editor.exec(‘selectall’);justifyleft左对齐editor.exec(‘justifyleft’);justifycenter居中editor.exec(‘justifycenter’);justifyright右对齐editor.exec(‘justifyright’);justifyfull两端对齐editor.exec(‘justifyfull’);insertorderedlist编号editor.exec(‘insertorderedlist’);insertunorderedlist项目符号editor.exec(‘insertunorderedlist’);indent增加缩进editor.exec(‘indent’);outdent减少缩进editor.exec(‘outdent’);subscript下标editor.exec(‘subscript’);superscript上标editor.exec(‘superscript’);cut剪切editor.exec(‘cut’);copy复制editor.exec(‘copy’);paste粘贴editor.exec(‘paste’);