- 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’);