zoukankan      html  css  js  c++  java
  • 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’);







    经验在于积累----武二郎
  • 相关阅读:
    JAVA相关基础的知识吧
    Java测试调用.net 接口服务
    Java测试内存信息
    Java测试普通Java接口记录-TestHrmInterface
    那些年学不会的操作(写法/...)——记录一些靠搜索做过但总是记不住的东西
    正确的sybase批量插入语法
    新ZJJG项目相关接口开发记录-微信制证组成浅析
    bip项目的启用/调试+ 问题记录
    记录数组问题
    模糊匹配的查询条件/ 给下拉框加提示呢
  • 原文地址:https://www.cnblogs.com/zhanghai/p/4461213.html
Copyright © 2011-2022 走看看