execCommand方法是执行一个对当前文档,当前选择或者给出范围的命令。处理Html数据时常用
如下格式:document.execCommand(sCommand[,交互方式, 动态参数]) ,其中:sCommand为指令参数(如下例中的”2D-Position”),交互方式参数如果是true的话将显示对话框,如果为false的话,则不显示对话框(下例中的”false”即表示不显示对话框),动态参数一般为一可用值或属性值(如下例中的”true”)。

document.execCommand("2D-Position","false","true");
下面列出的是指令参数及意义 2D-Position 允许通过拖曳移动绝对定位的对象。
AbsolutePosition 设定元素的 position 属性为“absolute”(绝对)。
BackColor 设置或获取当前选中区的背景颜色。
BlockDirLTR 目前尚未支持。
BlockDirRTL 目前尚未支持。
Bold 切换当前选中区的粗体显示与否。
BrowseMode 目前尚未支持。
Copy 将当前选中区复制到剪贴板。
CreateBookmark 创建一个书签锚或获取当前选中区或插入点的书签锚的名称。
CreateLink 在当前选中区上插入超级链接,或显示一个对话框允许用户指定要为当前选中区插入的超级链接的 URL。
Cut 将当前选中区复制到剪贴板并删除之。
Delete 删除当前选中区。
DirLTR 目前尚未支持。
DirRTL 目前尚未支持。
EditMode 目前尚未支持。
FontName 设置或获取当前选中区的字体。
FontSize 设置或获取当前选中区的字体大小。
ForeColor 设置或获取当前选中区的前景(文本)颜色。
FormatBlock 设置当前块格式化标签。
Indent 增加选中文本的缩进。
InlineDirLTR 目前尚未支持。
InlineDirRTL 目前尚未支持。
InsertButton 用按钮控件覆盖当前选中区。
InsertFieldset 用方框覆盖当前选中区。
InsertHorizontalRule 用水平线覆盖当前选中区。
InsertIFrame 用内嵌框架覆盖当前选中区。
InsertImage 用图像覆盖当前选中区。
InsertInputButton 用按钮控件覆盖当前选中区。
InsertInputCheckbox 用复选框控件覆盖当前选中区。
InsertInputFileUpload 用文件上载控件覆盖当前选中区。
InsertInputHidden 插入隐藏控件覆盖当前选中区。
InsertInputImage 用图像控件覆盖当前选中区。
InsertInputPassword 用密码控件覆盖当前选中区。
InsertInputRadio 用单选钮控件覆盖当前选中区。
InsertInputReset 用重置控件覆盖当前选中区。
InsertInputSubmit 用提交控件覆盖当前选中区。
InsertInputText 用文本控件覆盖当前选中区。
InsertMarquee 用空字幕覆盖当前选中区。
InsertOrderedList 切换当前选中区是编号列表还是常规格式化块。
InsertParagraph 用换行覆盖当前选中区。
InsertSelectDropdown 用下拉框控件覆盖当前选中区。
InsertSelectListbox 用列表框控件覆盖当前选中区。
InsertTextArea 用多行文本输入控件覆盖当前选中区。
InsertUnorderedList 切换当前选中区是项目符号列表还是常规格式化块。
Italic 切换当前选中区斜体显示与否。
JustifyCenter 将当前选中区在所在格式化块置中。
JustifyFull 目前尚未支持。
JustifyLeft 将当前选中区所在格式化块左对齐。
JustifyNone 目前尚未支持。
JustifyRight 将当前选中区所在格式化块右对齐。
LiveResize 迫使 MSHTML 编辑器在缩放或移动过程中持续更新元素外观,而不是只在移动或缩放完成后更新。
MultipleSelection 允许当用户按住 Shift 或 Ctrl 键时一次选中多于一个站点可选元素。
Open 目前尚未支持。
Outdent 减少选中区所在格式化块的缩进。
OverWrite 切换文本状态的插入和覆盖。
Paste 用剪贴板内容覆盖当前选中区。
PlayImage 目前尚未支持。
Print 打开打印对话框以便用户可以打印当前页。
Redo 目前尚未支持。
Refresh 刷新当前文档。
RemoveFormat 从当前选中区中删除格式化标签。
RemoveParaFormat 目前尚未支持。
SaveAs 将当前 Web 页面保存为文件。
SelectAll 选中整个文档。
SizeToControl 目前尚未支持。
SizeToControlHeight 目前尚未支持。
SizeToControlWidth 目前尚未支持。
Stop 目前尚未支持。
StopImage 目前尚未支持。
StrikeThrough 目前尚未支持。
Subscript 目前尚未支持。
Superscript 目前尚未支持。
UnBookmark 从当前选中区中删除全部书签。
Underline 切换当前选中区的下划线显示与否。
Undo 目前尚未支持。
Unlink 从当前选中区中删除全部超级链接。
Unselect 清除当前选中区的选中状态。

document.ExecCommand() – html实例

<HTML>

     <HEAD>

         <TITLE>JavaScript--execCommand指令集</TITLE>

         <SCRIPT LANGUAGE="javascript">

<!--

/*

*该function执行copy指令

*/

function fn_doufucopy(){

edit.select();

document.execCommand('Copy');

}

/*

*该function执行paste指令

*/

function fn_doufupaste() { 

tt.focus();

document.execCommand('paste');

} 

/*

*该function用来创建一个超链接

*/

function fn_creatlink()

{

  document.execCommand('CreateLink',true,'true');//弹出一个对话框输入URL

  //document.execCommand('CreateLink',false,'http://www.51js.com');

}

/*

*该function用来将选中的区块设为指定的背景色

*/

function fn_change_backcolor()

{

  document.execCommand('BackColor',true,'#FFbbDD');//true或false都可以

}

/*

*该function用来将选中的区块设为指定的前景色,改变选中区块的字体大小,改变字体,字体变粗变斜

*/

function fn_change_forecolor()

{

//指定前景色

document.execCommand('ForeColor',false,'#BBDDCC');//true或false都可以

//指定背景色

document.execCommand('FontSize',false,7);   //true或false都可以

//字体必须是系统支持的字体

document.execCommand('FontName',false,'标楷体');   //true或false都可以

//字体变粗

document.execCommand('Bold');

//变斜体

document.execCommand('Italic');

}

/*

*该function用来将选中的区块加上不同的线条

*/

function fn_change_selection()

{

//将选中的文字加下划线

document.execCommand('Underline');

//在选中的文字上划粗线

document.execCommand('StrikeThrough');

//将选中的部分文字变细

document.execCommand('SuperScript');

//将选中区块的下划线取消掉

document.execCommand('Underline'); 

}

/*

  *该function用来将选中的区块排成不同的格式

  */

function fn_format()

{

//有序列排列

document.execCommand('InsertOrderedList');

//实心无序列排列

document.execCommand('InsertUnorderedList');

//空心无序列排列

document.execCommand('Indent');

}

/*

*该function用来将选中的区块剪下或是删除掉

*/

function fn_CutOrDel()

{

//删除选中的区块

//document.execCommand('Delete');

//剪下选中的区块

document.execCommand('Cut');

}

/*

*该function用来将选中的区块重设为一个相应的物件

*/

function fn_InsObj()

{

/*

  ******************************************

  * 以下指令都是为选中的区块重设一个object;

  * 如没有特殊说明,第二个参数true或false是一样的;

  * 参数三表示为该object的id;

  * 可以用在javascript中通过其指定的id来控制它

  ******************************************

*/

/*重设为一个button(InsertButton和InsertInputButtong一样,

只不前者是button,后者是input)*/

/*document.execCommand('InsertButton',false,"aa"); //true或false无效

document.all.aa.value="风舞九天";*/

//重设为一个fieldset

/*document.execCommand('InsertFieldSet',true,"aa");

document.all.aa.innerText="刀剑如梦";*/

//插入一个水平线

//document.execCommand('InsertHorizontalRule',true,"aa");

//插入一个iframe

//document.execCommand('InsertIFrame',true,"aa");

//插入一个InsertImage,设为true时需要图片,false时不需图片

//document.execCommand('InsertImage',false,"aa");

//插入一个checkbox

//document.execCommand('InsertInputCheckbox',true,"aa");

//插入一个file类型的object

//document.execCommand('InsertInputFileUpload',false,"aa");

//插入一个hidden

/*document.execCommand('InsertInputHidden',false,"aa");

alert(document.all.aa.id);*/

//插入一个InputImage

/*document.execCommand('InsertInputImage',false,"aa");

document.all.aa.src="F-a10.gif";*/

//插入一个Password

//document.execCommand('InsertInputPassword',true,"aa");

//插入一个Radio

//document.execCommand('InsertInputRadio',false,"aa");

//插入一个Reset

//document.execCommand('InsertInputReset',true,"aa");

//插入一个Submit

//document.execCommand('InsertInputSubmit',false,"aa");

//插入一个input text

//document.execCommand('InsertInputText',false,"aa");

//插入一个textarea

//document.execCommand('InsertTextArea',true,"aa");

//插入一个 select list box

//document.execCommand('InsertSelectListbox',false,"aa");

//插入一个single select

document.execCommand('InsertSelectDropdown',true,"aa");

//插入一个line break(硬回车??)

//document.execCommand('InsertParagraph');

//插入一个marquee

/*document.execCommand('InsertMarquee',true,"aa");

document.all.aa.innerText="bbbbb";*/

//用于取消选中的阴影部分

//document.execCommand('Unselect');

//选中页面上的所有元素

//document.execCommand('SelectAll');

}

/*

*该function用来将页面保存为一个文件

*/

function fn_save()

{

//第二个参数为欲保存的文件名

document.execCommand('SaveAs','mycodes.txt');

//打印整个页面

//document.execCommand('print');

}

--> 

         </SCRIPT>

     </HEAD>

     <body>

         <input id="edit" value="范例" NAME="edit"><br>

         <button onclick="fn_doufucopy()" ID="Button1">Copy</button> <button onclick="fn_doufupaste()" ID="Button2">

              paste</button><br>

         <textarea id="tt" rows="10" cols="50" NAME="tt"></textarea>

         <hr>

         <br>

         浮沉聚散变化又再,但是总可卷土重来.<br>

         天若有情天亦老,人间正道是沧桑.<br>

         都怪我,太执着,却也等不到花开叶落.<br>

         <br>

         Please select above letters, then click following buttons:<br>

         <hr>

         <input type="button" value="创建CreateLink" onclick="fn_creatlink()" ID="Button3" NAME="Button3"><br>

         <input type="button" value="改变文字背景色" onclick="fn_change_backcolor()" ID="Button4" NAME="Button4"><br>

         <input type="button" value="改变文字前景色" onclick="fn_change_forecolor()" ID="Button5" NAME="Button5"><br>

         <input type="button" value="给文字加线条" onclick="fn_change_selection()" ID="Button6" NAME="Button6"><br>

         <input type="button" value="改变文字的排列" onclick="fn_format()" ID="Button7" NAME="Button7"><br>

         <input type="button" value="删除或剪下选中的部分" onclick="fn_CutOrDel()" ID="Button8" NAME="Button8"><br>

         <input type="button" value="插入Object" onclick="fn_InsObj()" ID="Button9" NAME="Button9"><br>

         <input type="button" value="保存或打印文件" onclick="fn_save()" ID="Button10" NAME="Button10"><br>

         <input type="button" value="测试Refresh属性" onclick="document.execCommand('Refresh')" ID="Button11"

              NAME="Button11">

     </body>

</HTML>

JavaScript中的execCommand()命令详解及实例展示的更多相关文章

  1. javascript中ClassName属性的详解与实例

    在javascritp中,我们可以通过style属性可以控制元素的样式,从而实现行为层通过DOM的style属性去干预显示层显示的目标,但是这种方法是不好的,而且为了实现通过DOM脚本设置的样式,你不 ...

  2. javascript中=、==、===区别详解

    javascript中=.==.===区别详解今天在项目开发过中发现在一个小问题.在判断n==""结果当n=0时 n==""结果也返回了true.虽然是个小问题 ...

  3. JavaScript中return的用法详解

    JavaScript中return的用法详解 最近,跟身边学前端的朋友了解,有很多人对函数中的this的用法和指向问题比较模糊,这里写一篇博客跟大家一起探讨一下this的用法和指向性问题. 1定义 t ...

  4. javascript 中合并排序算法 详解

    javascript 中合并排序算法 详解 我会通过程序的执行过程来给大家合并排序是如何排序的...  合并排序代码如下: <script type="text/javascript& ...

  5. javascript中的this作用域详解

    javascript中的this作用域详解 Javascript中this的指向一直是困扰我很久的问题,在使用中出错的机率也非常大.在面向对象语言中,它代表了当前对象的一个引用,而在js中却经常让我觉 ...

  6. JavaScript中this的用法详解

    JavaScript中this的用法详解 最近,跟身边学前端的朋友了解,有很多人对函数中的this的用法和指向问题比较模糊,这里写一篇博客跟大家一起探讨一下this的用法和指向性问题. 1定义 thi ...

  7. Linux下的压缩zip,解压缩unzip命令详解及实例

    实例:压缩服务器上当前目录的内容为xxx.zip文件 zip -r xxx.zip ./* 解压zip文件到当前目录 unzip filename.zip ====================== ...

  8. groupadd命令详解(实例)

     groupadd命令详解(实例)  1.作用groupadd命令用于将新组加入系统. 2.格式groupadd [-g gid] [-o]] [-r] [-f] groupname 3.主要参数-g ...

  9. Linux下的压缩解压缩命令详解及实例

    实例:压缩服务器上当前目录的内容为xxx.zip文件 zip -r xxx.zip ./* 解压zip文件到当前目录 unzip filename.zip ====================== ...

随机推荐

  1. 开展.net mvc3遇到怪事+解

    发展到今天.net mvc3遇到怪事. 使用Firefox浏览器.打开index页,求index该控制器是很多次,代码查询数据库的多个运行.server减速. 而且没有刷新页面,随着时间的推移有十二请 ...

  2. HDU 3366 Passage (概率DP)

    Passage Problem Description Bill is a millionaire. But unfortunately he was trapped in a castle. The ...

  3. ASP.NET Identity 身份验证和基于角色的授权

    ASP.NET Identity 身份验证和基于角色的授权 阅读目录 探索身份验证与授权 使用ASP.NET Identity 身份验证 使用角色进行授权 初始化数据,Seeding 数据库 小结 在 ...

  4. 浙江大学PAT考试1069~1072(2013-11-2)

    11 题目地址:http://pat.zju.edu.cn/contests/pat-a-practise 1069: 由下降序和上升序两个四位数不断相减,然后得到新数据,始终会到达一个数字终止. 递 ...

  5. android使用ffmpeg

    cygwin上文编译文章. 在ffmpeg/arm添加的文件夹Android.mk 的主要目的是为了宣布动态库libs下一个 LOCAL_PATH:= $(call my-dir) include $ ...

  6. Yeoman generators 创建 ASP.NET 应用程序

    Yeoman generators 创建 ASP.NET 应用程序 上一篇:<Windows 搭建 .NET 跨平台环境并运行应用程序> 阅读目录: Install Node.js Ins ...

  7. 去除win7 64位系统桌面图标小箭头

    http://blog.csdn.net/pipisorry/article/details/24865195 在桌面新建一个文本文档 去除箭头.txt,把例如以下代码粘贴到文档中reg add &q ...

  8. CentOS-6.5-x86_64 最小化安装,已安装包的总数,这些包?

    一.我们怎么知道有多少的包被安装? [root@localhost ~]# rpm -qa | wc -l 217 二.怎样得知安装了那些软件包? [root@localhost ~]# rpm -q ...

  9. 【百度地图API】如何制作泡泡放大镜?

    原文:[百度地图API]如何制作泡泡放大镜? 任务描述: 我不喜欢API提供的缩放控件耶…… 我能不能使用其他方式放大地图勒? 当然阔以啦! 现在就来教大家如何动手制作一个可爱的泡泡放大镜! 使用它, ...

  10. MySQL 升级方法指南大全

    原文:MySQL 升级方法指南大全 通常,从一个发布版本升级到另一个版本时,我们建议按照顺序来升级版本.例如,想要升级 MySQL 3.23 时,先升级到 MySQL 4.0,而不是直接升级到 MyS ...