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 清除当前选中区的选中状态。
更实用的例子:
<button onclick="document.execCommand('CreateLink')">创建连接</button>
分享到:
相关推荐
javascript 的execCommand和操作剪贴板的收集
execCommand指令集详解,javascript进阶是常用的参考资料
主要给大家介绍在JavaScript中如何解决用execCommand("SaveAS")保存页面兼容性问题,设计到execCommand兼容性问题,感兴趣的朋友可以参考下本
dom下execCommand命令的一些参数整理,需要的朋友可以参考下。
一个非常简单的包装器,用于在 NodeJS 中同步执行系统命令! 包装器正在使用 。 例子 var execCommand = require ( "execCommand.js" ) ; var command = execCommand ( "cat /sys/class/thermal/thermal_zone0/...
事件源对象 event.srcElement.tagName event.srcElement.type •捕获释放 event.srcElement.setCapture(); event.srcElement.releaseCapture(); •事件按键 ...document.execCommand ......
document.execCommand 窗体COOKIE document.cookie 菜单事件 document.oncontextmenu 创建元素 document.createElement("SPAN"); 根据鼠标获得元素: document.elementFromPoint(event.x,event.y).tagName==...
IE浏览器用document.execCommand(“Stop”),Chrome和Firefox用window.stop()(顺便说下,这是JavaScript标准中定义的方法),写在一起就是下面的方式了: <html> <body> 这里可以显示 [removed] if ...
contentEditables 中 document.execCommand 的一个稍微甜一点的 api。 目标: 公开一个更容易发现的 api 以在 contentEditables 中使用。 由 DIY WYSIWYG 工具栏控制的基本功能 无依赖 ~200 行(5k-ish 未压缩) ...
Javascript刷新页面的实例 Javascript刷新页面的几种方法: 1 history.go(0) 2 location.reload() ...5 document.execCommand(‘Refresh’) 6 window.navigate(location) 7 location.replace(location)
Javascript刷新页面的几种方法: 代码如下:1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(location) 5 document.execCommand(‘Refresh’) 6 window.navigate(location) 7 location....
Javascript刷新页面的几种方法: 1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(location) 5 document.execCommand(‘Refresh’) 6 window.navigate(location) 7 location.replace...
document.execCommand(Copy); // 执行浏览器复制命令 alert(已复制好,可贴粘。); } [removed] <textarea cols=20 rows=10 id=biao1>用户定义的代码区域</textarea> <input type=button o
1)、通过 document.execCommand('copy') 2)、前端代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>constructor-nodelist</title> ...
剪贴画clipbrd 是一个普通的 javascript 复制到剪贴板小部件。 它使用“document.execCommand('copy')”函数。浏览器支持Chrome v42 火狐 v41 Internet Explorer v9 歌剧 v29用法 clipbrd . copy ( 'test1234' , // ...
ssh-exec, 使用 node.js 在ssh上执行脚本 ssh在ssh上执行脚本,使用 node.js 和管道,并从可以通过npm提供。npm install ssh-exec它是用普通的Javascript编写的,使用了 ssh2作为所有重。用法var ex
JS只能输入数字,数字和字母等的正则表达式 1.文本框只能输入数字代码(小数点也...input onkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')"> <input name=txt1
document.execCommand("copy", false); document.execCommand()方法功能很强大,了解更多请戳:https://developer.mozilla.org/zh-CN/docs/Web/API/Document/execCommand 正文: 调用以上方法,就实现了copy功能...