zoukankan      html  css  js  c++  java
  • 【编辑器开发】基本js指令

    最近在研究编辑器的开发,这方面的东西网上的例子比较少,因为大家都在用免费的编辑器,或别人开发好的,这种编辑器大多都是用js写的,今天在网上找了一篇比较全的execCommand事件的重载方法,全转过来供以后查询。
    ID.document.designMode="on" 使iframe处在可编辑状态为off时为不可以编辑
    ID.focus(); 获取当前iframe的焦点
    ID.document.selection.createRange(); 获取文本框中选中区内容
    ID.document.execCommand(s); 在当前文档、选中区或给定范围上执行命令
    execCommand参数
    ID.document.execCommand('Cut'); 剪切
    ID.document.execCommand('Copy') 拷贝
    ID.document.execCommand('Paste') 粘贴
    ID.document.execCommand('Undo') 撤消
    ID.document.execCommand('Redo') 重做
    ID.document.execCommand('Delete') 删除
    ID.document.execCommand('Bold') 黑体
    ID.document.execCommand('Italic') 斜体
    ID.document.execCommand('Underline') 下划线
    ID.document.execCommand('StrikeThrough'); 在选中的文字上划粗线
    ID.document.execCommand('SuperScript'); 将选中的部分文字变细
    ID.document.execCommand('Underline'); 将选中区块的下划线取消掉
    ID.document.execCommand('stop') 停止
    ID.document.execCommand('SaveAs') 保存
    ID.document.execCommand('Saveas',false,'c:\\test.htm') 另存为
    ID.document.execCommand('FontName',false,'标楷体') 字体字体必须是系统支持的字体true或false都可以
    ID.document.execCommand('FontSize',false,fs) 字体大小
    ID.document.execCommand('refresh',false,0) 刷新
    ID.document.execCommand('CreateLink',true,'true') 弹出一个对话框输入URL创建一个超链接
    ID.document.execCommand('CreateLink',false,'http://www.51js.com') 创建一个超链接
    ID.document.execCommand('BackColor',true,'#FFbbDD') 将选中的区块设为指定的背景色true或false都可以
    ID.document.execCommand('ForeColor',false,'#BBDDCC') 指定前景色true或false都可以
    ID.document.execCommand('FontSize',false,7) 指定背景色true或false都可以
    ID.document.execCommand('InsertOrderedList') 有序列排列
    ID.document.execCommand('InsertUnorderedList') 实心无序列排列
    ID.document.execCommand('Indent') 空心无序列排列
    ID.document.execCommand('Delete') 删除选中的区块
    ID.document.execCommand('Cut') 剪下选中的区块
    表单类
    ID.document.execCommand('InsertButton',false,"aa") 新增加一个Button true或false无效 document.all.aa.value="风舞九天"
    ID.document.execCommand('InsertInputButtong',false,"aa") 新增加一个input true或false无效 document.all.aa.value="风舞九天"
    ID.document.execCommand('InsertFieldSet',true,"aa") 重设为一个fieldset document.all.aa.innerText="刀剑如梦"
    ID.document.execCommand('InsertHorizontalRule',true,"aa") 插入一个水平线
    ID.document.execCommand('InsertIFrame',true,"aa") 插入一个iframe
    ID.document.execCommand('InsertImage',false,"aa") 插入一个InsertImage,设为true时需要图片,false时不需图片
    ID.document.execCommand('InsertInputCheckbox',true,"aa") 插入一个checkbox
    ID.document.execCommand('InsertInputFileUpload',false,"aa") 插入一个file类型的object
    ID.document.execCommand('InsertInputHidden',false,"aa") 插入一个hidden
    ID.document.execCommand('InsertInputImage',false,"aa") 插入一个InputImage document.all.aa.src="F-a10.gif";
    ID.document.execCommand('InsertInputPassword',true,"aa") 插入一个Password
    ID.document.execCommand('InsertInputRadio',false,"aa") 插入一个Radio
    ID.document.execCommand('InsertInputReset',true,"aa") 插入一个Reset
    ID.document.execCommand('InsertInputSubmit',false,"aa") 插入一个Submit
    ID.document.execCommand('InsertInputText',false,"aa") 插入一个input text
    ID.document.execCommand('InsertTextArea',true,"aa") 插入一个textarea
    ID.document.execCommand('InsertSelectListbox',false,"aa") 插入一个 select list box
    ID.document.execCommand('InsertSelectDropdown',true,"aa") 插入一个single select
    ID.document.execCommand('InsertParagraph') 插入一个line break(硬回车??)
    ID.document.execCommand('InsertMarquee',true,"aa") 插入一个marquee document.all.aa.innerText="bbbbb"
    ID.document.execCommand('Unselect') 于取消选中的阴影部分
    ID.document.execCommand('SelectAll') 选中页面上的所有元素
    ID.document.execCommand('SaveAs','mycodes.txt'); 第二个参数为欲保存的文件名
    ID.document.execCommand('print') 打印整个页面
    ID.document.execCommand("SuperScript") 上标
    ID.document.execCommand("SubScript") 下标
    ID.document.execCommand("Outdent") 向前缩进
    ID.document.execCommand("Indent") 向后缩进
    ID.document.execCommand("JustifyLeft") 居左
    ID.document.execCommand("JustifyRight") 居右
    ID.document.execCommand("JustifyCenter") 居中
    ID.document.execCommand("ForeColor","",CColor) 字体颜色
    在焦点位置上插入html
    ID.focus(); //获取当前iframe的焦点
    o = ID.document.selection.createRange();//获取文本框中选中区内容
    o.pasteHTML("<img src=\"\" width=\"100\" height=\"100\">")

    作者:罗敏贵
    邮箱:minguiluo@163.com
    QQ群:34178394 建群 主要是寻找志同道合的人士一起学习和讨论自己的所学所思
    出处:http://luomingui.cnblogs.com/
    说明:专注于微软平台项目架构、熟悉设计模式、架构设计、敏捷个人和项目管理。现主要从事WinForm、ASP.NET、等方面的项目开发、架构、管理工作。文章为作者平时里的思考和练习,可能有不当之处,请博客园的园友们多提宝贵意见。
    知识共享许可协议本作品采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可。

  • 相关阅读:
    Atom + activate-power-mode震屏插件Windows7下安装
    通过Google身份验证器加强Linux帐户安全
    adb 常用命令总结
    excel 文件加密
    docker 进入容器命令行 /bin/bash 后不支持中文
    无法获取 gcr.io 上的镜像的解决方法
    mysql unix 时间戳转换
    docker 镜像如何导入导出以及建立自己的镜像仓库
    asp.net core 文件的处理
    docker compose 设置环境变量
  • 原文地址:https://www.cnblogs.com/luomingui/p/1673909.html
Copyright © 2011-2022 走看看