现在的位置: 首页 > 综合 > 正文

【编辑器开发】基本js指令

2012年11月22日 ⁄ 综合 ⁄ 共 3783字 ⁄ 字号 评论关闭
最近在研究编辑器的开发,这方面的东西网上的例子比较少,因为大家都在用免费的编辑器,或别人开发好的,这种编辑器大多都是用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\">")

抱歉!评论已关闭.