Kindeditor中實用的編輯器api詳解和實例用法(一)


  • K.create(expr [, options])
創建編輯器,返回第一個KEditor對象。4.1版本開始expr支持多個textarea,之前版本只在第一個textarea上創建。
創建編輯器后可以用 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()
取得編輯器的HTML內容。
參數: 無
返回: string
示例:

1var html = editor.html();

  • html(val)
設置編輯器的HTML內容。
參數:
string val: HTML
返回: KEditor
示例:

1editor.html('<strong>HTML</strong> code');

  • fullHtml()
取得完整的HTML內容,HTML包含<html>標簽。
參數: 無
返回: string
示例:

1var fullHtml = editor.fullHtml();

  • text()
取得編輯器的純文本內容。(包含img和embed)
參數: 無
返回: string
示例:

1var text = editor.text();

  • text(val)
設置編輯器的內容,直接顯示HTML代碼。
參數:
string val: 文本
返回: KEditor
示例:

1editor.text('<strong>HTML</strong> code');

  • selectedHtml()
取得當前被選中的HTML內容。
參數: 無
返回: string
示例:

1var html = editor.selectedHtml();

  • count([mode])
取得當前被選中的HTML內容。
參數:
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)
將指定的HTML內容插入到編輯區域里的光標處。
參數:
string val: HTML
返回: KEditor
示例:

1editor.insertHtml('<strong>HTML</strong> code');

  • appendHtml(val)
將指定的HTML內容添加到編輯區域的最后位置。
參數:
string val: HTML
返回: KEditor
示例:

1editor.appendHtml('<strong>HTML</strong> code');

  • focus()
編輯器聚焦。
參數: 無
返回: KEditor
示例:

1editor.focus();

  • blur()

編輯器失去焦點。
參數: 無
返回: KEditor
示例:

1editor.blur();

  • sync()
將編輯器的內容設置到原來的textarea控件里。
參數: 無
返回: KEditor
示例:

1editor.sync();

  • exec(commandName)
執行編輯命令,替代document.execCommmand接口。
參數:
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’);








免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM