document.execCommand()函数可用参数解析
隐藏在暗处的方法-execCommand()
关键字: javascript document
document.execCommand()方法可用来执行很多我们无法实现的操作.
execCommand方法是执行一个对当前文档,当前选择或者给出范围的命令。
document.execCommand()方法处理Html数据时常用语法格式如下: 复制内容到剪贴板
代码:
document.execCommand(sCommand[,交互方式, 动态参数]) 其中:sCommand为指令参数(如下例中的"2D-Position"),交互方式参数如果是true的话将显示对话框,如果为false的话,则不显示对话框(下例中的"false"即表示不显示对话框),动态参数一般为一可用值或属性值(如下例中的"true")。
document.execCommand("2D-Position","false","true");
调用execCommand()可以实现浏览器菜单的很多功能. 如保存文件,打开新文件,撤消、重做操作...等等. 有了这个方法,就可以很容易的实现网页中的文本编辑器.
如果灵活运用,可以很好的辅助我们完成各种项目.
使用的例子如下:
1、〖全选〗命令的实现
[格式]:document.execCommand("selectAll")
[说明]将选种网页中的全部内容!
[举例]在<body></body>之间加入:
<a href="#" onclick=document.execCommand("selectAll")>全选</a>
2、〖打开〗命令的实现
[格式]:document.execCommand("open")
[说明]这跟VB等编程设计中的webbrowser控件中的命令有些相似,大家也可依此琢磨琢磨。
[举例]在<body></body>之间加入:
<a href="#" onclick=document.execCommand("open")>打开</a>
3、〖另存为〗命令的实现
[格式]:document.execCommand("saveAs")
[说明]将该网页保存到本地盘的其它目录!
[举例]在<body></body>之间加入:
<a href="#" onclick=document.execCommand("saveAs")>另存为</a>
4、〖打印〗命令的实现
[格式]:document.execCommand("print")
[说明]当然,你必须装了打印机!
[举例]在<body></body>之间加入:
<a href="#" onclick=document.execCommand("print")>打印</a>
Js代码 下面列出的是指令参数及意义
//相当于单击文件中的打开按钮
document.execCommand("Open");
//将当前页面另存为
document.execCommand("SaveAs");
//剪贴选中的文字到剪贴板;
document.execCommand("Cut","false",null);
//删除选中的文字;
document.execCommand("Delete","false",null);
//改变选中区域的字体;
document.execCommand("FontName","false",sFontName);
//改变选中区域的字体大小;
document.execCommand("FontSize","false",sSize|iSize);
//设置前景颜色;
document.execCommand("ForeColor","false",sColor);
//使绝对定位的对象可直接拖动;
document.execCommand("2D-Position","false","true");
//使对象定位变成绝对定位;
document.execCommand("AbsolutePosition","false","true");
//设置背景颜色;
document.execCommand("BackColor","false",sColor);
//使选中区域的文字加粗;
document.execCommand("Bold","false",null);
//复制选中的文字到剪贴板;
document.execCommand("Copy","false",null);
//设置指定锚点为书签;
document.execCommand("CreateBookmark","false",sAnchorName);
//将选中文本变成超连接,若第二个参数为true,会出现参数设置对话框;
document.execCommand("CreateLink","false",sLinkURL);
//设置当前块的标签名;
document.execCommand("FormatBlock","false",sTagName);
//相当于单击文件中的打开按钮
document.execCommand("Open");
//将当前页面另存为
document.execCommand("SaveAs");
//剪贴选中的文字到剪贴板;
document.execCommand("Cut","false",null);
//删除选中的文字;
document.execCommand("Delete","false",null);
//改变选中区域的字体;
document.execCommand("FontName","false",sFontName);
//改变选中区域的字体大小;
document.execCommand("FontSize","false",sSize|iSize);
//设置前景颜色;
document.execCommand("ForeColor","false",sColor);
//使绝对定位的对象可直接拖动;
document.execCommand("2D-Position","false","true");
//使对象定位变成绝对定位;
document.execCommand("AbsolutePosition","false","true");
//设置背景颜色;
document.execCommand("BackColor","false",sColor);
//使选中区域的文字加粗;
document.execCommand("Bold","false",null);
//复制选中的文字到剪贴板;
document.execCommand("Copy","false",null);
//设置指定锚点为书签;
document.execCommand("CreateBookmark","false",sAnchorName);
//将选中文本变成超连接,若第二个参数为true,会出现参数设置对话框;
document.execCommand("CreateLink","false",sLinkURL);
//设置当前块的标签名;
document.execCommand("FormatBlock","false",sTagName);
另外:document.execCommand()还有很多的其它属性.以下是我搜集整理的.可能还漏了很多,希望大家多多补充!
2D-Position 允许通过拖曳移动绝对定位的对象。
AbsolutePosition 设定元素的 position 属性为“absolute”(绝对)。
BackColor 设置或获取当前选中区的背景颜色。
Bold 切换当前选中区的粗体显示与否。
Copy 将当前选中区复制到剪贴板。
CreateBookmark 创建一个书签锚或获取当前选中区或插入点的书签锚的名称。
CreateLink 在当前选中区上插入超级链接,或显示一个对话框允许用户指定要为当前选中区插入的超级链接的 URL。
Cut 将当前选中区复制到剪贴板并删除之。
Delete 删除当前选中区。
FontName 设置或获取当前选中区的字体。
FontSize 设置或获取当前选中区的字体大小。
ForeColor 设置或获取当前选中区的前景(文本)颜色。
FormatBlock 设置当前块格式化标签。
Indent 增加选中文本的缩进。
InsertButton 用按钮控件覆盖当前选中区。
InsertFieldset 用方框覆盖当前选中区。
InsertHorizontalRule 用水平线覆盖当前选中区。
InsertIFrame 用内嵌框架覆盖当前选中区。
InsertImage 用图像覆盖当前选中区。
InsertInputButton 用按钮控件覆盖当前选中区。
InsertInputCheckbox 用复选框控件覆盖当前选中区。
InsertInputFileUpload 用文件上载控件覆盖当前选中区。
InsertInputHidden 插入隐藏控件覆盖当前选中区。
InsertInputImage 用图像控件覆盖当前选中区。
InsertInputPassword 用密码控件覆盖当前选中区。
InsertInputRadio 用单选钮控件覆盖当前选中区。
InsertInputReset 用重置控件覆盖当前选中区。
InsertInputSubmit 用提交控件覆盖当前选中区。
InsertInputText 用文本控件覆盖当前选中区。
InsertMarquee 用空字幕覆盖当前选中区。
InsertOrderedList 切换当前选中区是编号列表还是常规格式化块。
InsertParagraph 用换行覆盖当前选中区。
InsertSelectDropdown 用下拉框控件覆盖当前选中区。
InsertSelectListbox 用列表框控件覆盖当前选中区。
InsertTextArea 用多行文本输入控件覆盖当前选中区。
InsertUnorderedList 切换当前选中区是项目符号列表还是常规格式化块。
Italic 切换当前选中区斜体显示与否。
JustifyCenter 将当前选中区在所在格式化块置中。
JustifyLeft 将当前选中区所在格式化块左对齐。
JustifyRight 将当前选中区所在格式化块右对齐。
LiveResize 迫使 MSHTML 编辑器在缩放或移动过程中持续更新元素外观,而不是只在移动或缩放完成后更新。
MultipleSelection 允许当用户按住 Shift 或 Ctrl 键时一次选中多于一个站点可选元素。
Open 打开一个文档。
Outdent 减少选中区所在格式化块的缩进。
OverWrite 切换文本状态的插入和覆盖。
Paste 用剪贴板内容覆盖当前选中区。
Print 打开打印对话框以便用户可以打印当前页。
Redo 撤消操作,相当于Ctrl+Z。
Undo 重做。
Refresh 刷新当前文档。
RemoveFormat 从当前选中区中删除格式化标签。
RemoveParaFormat 目前尚未支持。
SaveAs 将当前 Web 页面保存为文件。
SelectAll 选中整个文档。
UnBookmark 从当前选中区中删除全部书签。
Underline 切换当前选中区的下划线显示与否。
Unlink 从当前选中区中删除全部超级链接。
Unselect 清除当前选中区的选中状态。
------------------------------------------------------------------------------------
Javascript的世界真是奇妙. 有时,只是一次不经意的google,都会发现一些以前没见过,或忽略的语法. 当用起来的时候,才发现它的威力. 不知还有多少正隐藏在暗处的方法,等着你我去发现?
------------------------------------------------------------------------------------
(部分内容来源于百度搜索)
document.execCommand()函数可用参数解析
<html>
<head>
<title>javascript--execcommand指令集</title>
<script type="text/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://bbs.tc800.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用来将选中的区块重设为一个相应的物件
*/
document.execCommand()的应用实例
document.execCommand()的应用实例
本文来自: 盛世唐朝社区(http://bbs.tc800.com)
详细出处:http://bbs.tc800.com/thread-23658-1-1.html
<input type="button" value="剪切" onclick="document.execCommand('Cut')">
<input type="button" value="拷贝" onclick="document.execCommand('Copy')">
<input type="button" value="粘贴" onclick="document.execCommand('Paste')">
<input type="button" value="撤消" onclick="document.execCommand('Undo')">
<input type="button" value="重做" onclick="document.execCommand('Redo')" id="button2" name="button2">
<input>
<input type="button" value="删除" onclick="document.execCommand('Delete')">
<input type="button" value="黑体" onclick="document.execCommand('Bold')">
<input type="button" value="斜体" onclick="document.execCommand('Italic')">
<input type="button" value="下划线" onclick="document.execCommand('Underline')">
<input type="button" value="停止" onclick="document.execCommand('stop')">
<input type="button" value="保存" onclick="document.execCommand('SaveAs')">
<input type="button" value="另存为" onclick="document.execCommand('Saveas',false,'c:\\test.htm')">
<input type="button" value="字体" onclick="document.execCommand('FontName',false,fn)">
<input type="button" value="字体大小" onclick="document.execCommand('FontSize',false,fs)">
<input type="button" value="刷新" onclick="document.execCommand('refresh',false,0)">
本文来自: 盛世唐朝社区(http://bbs.tc800.com)
详细出处:http://bbs.tc800.com/thread-23658-1-1.html
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wwwchenbing/archive/2008/11/28/3402963.aspx
document.execCommand()函数可用参数解析的更多相关文章
- sqlalchemy query函数可用参数有哪些?
一.模型名 二.模型对象属性 三.聚合函数 下面就分别为大家讲讲query函数这三种参数的用法. 在讲之前,我已经把数据库连接配置.模型,以及添加数据写好了,代码如下: from sqlalchemy ...
- Hi3359AV100 NNIE开发(1)-RFCN demo LoadModel函数与参数解析
之后随笔将更多笔墨着重于NNIE开发系列,下文是关于Hi3359AV100 NNIE开发(1)-RFCN demo LoadModel函数与参数解析,通过对LoadModel函数的解析,能够很好理解. ...
- python中函数的参数解析
python中函数的各种参数梳理: 1.形参:函数定义时传入的参数 2.实参:函数调用时传入的参数 (有形参必传实参,形参里自身特点可不传的,可传可不传) 3.缺省参数:不传为默认值,传了会覆盖(下面 ...
- C语言中函数可变参数解析
大多数时候,函数中形式参数的数目通常是确定的,在调用时要依次给出与形式参数对应的所有实际参数.但在某些情况下希望函数的参数个数可以根据需要确定.典型的例子有 大家熟悉的函数printf().scanf ...
- C语言中的main函数的参数解析
main()函数既可以是无参函数,也可以是有参的函数.对于有参的形式来说,就需要向其传递参数.但是其它任何函数均不能调用main()函数.当然也同样无法向main()函数传递,只能由程序之外传递而来. ...
- 扩展Python模块系列(三)----参数解析与结果封装
在上一节中,通过一个简单的例子介绍了C语言扩展Python内建模块的整体流程,从本节开始讲开始深入讨论一些细节问题,在细节讨论中从始至终都会涉及[引用计数]的问题.首先讨论C语言封装的Python函数 ...
- [转]BX9054: 各浏览器对 document.execCommand 方法的首参数可选值范围存在差异
作者:钱宝坤 标准参考 无. 问题描述 execCommand 方法通常用于控制可编辑的 IFRAME 内容,制作富文本编辑器. 但他现在为止还是非标准的,方法的首参数 Commmands 的可选值由 ...
- Linux C编程--main函数参数解析
我们经常用的main函数都是不带参数的.因此main 后的括号都是空括号.实际上,main函数可以带参数,这个参数可以认为是 main函数的形式参数.C语言规定main函数的参数只能有两个, 习惯上这 ...
- JavaScripy execCommand函数
execCommand函数命令 execCommand方法是执行一个对当前文档,当前选择或者给出范围的命令.处理Html数据时常用如下格式:document.execCommand(sCommand[ ...
随机推荐
- codeforces 631D. Messenger kmp
题目链接 首先想到kmp, 和普通的不一样的是,中间部分严格相等, 头和尾的字符相等但是数量可以不相等. 所以应该把子串的头和尾先去掉,然后对剩下的部分进行kmp. 子串长度为1或2要特别讨论. 不要 ...
- python collections中Counter类
Counter是dict的一个子类,因此具有dict的属性与方法.如常用的iteritems, items, get, pop. class Counter(dict): 如果Key不存在,将返回0, ...
- HTML5速查表
HTML5速查表 标签 描述 版本 属性 <!--...--> 定义注释 4 / 5 none <!DOCTYPE> 定义文档类型 4 / 5 none <a> 定 ...
- 转:Grunt:任务自动管理工具
Grunt:任务自动管理工具 来自<JavaScript 标准参考教程(alpha)>,by 阮一峰 目录 安装 命令脚本文件Gruntfile.js Gruntfile.js实例:gru ...
- 基于MDK的ARM-GCC开发环境建立及新唐M0的HID类设备的C++开发
一,下载安装测试arm-none-eabi-gcc编译工具链 1,查看arm-none-eabi-gcc编译工具版本 打开网页:https://sourcery.mentor.com/G ...
- Select XML Nodes by Name [C#]
原文 http://www.csharp-examples.net/xml-nodes-by-name/ To find nodes in an XML file you can use XPath ...
- 如何使用 Android Studio 的 git hub 功能
How to use GitHub with Android Studio This article will explain how to use GitHub with Android Studi ...
- HTML5入门(一)
HTML简单介绍: HTML(HyperText Markup Language),超文本标记语言,是一种专门用于创建web的超文本文档编程语言,是我们看到的网页的源代码. 版本简介: 1997年推出 ...
- 安装cocopods 更新ruby
最近弄cocoapods出现如标题提示 So度娘一番.感谢作者.纯属学习没有商业用途 1.打开终端 终端输入 $ruby -v 查看ruby的版本 打印代码: ruby 2.0.0p648 (2 ...
- KMP算法的一次理解
1. 引言 在一个大的字符串中对一个小的子串进行定位称为字符串的模式匹配,这应该算是字符串中最重要的一个操作之一了.KMP本身不复杂,但网上绝大部分的文章把它讲混乱了.下面,咱们从暴力匹配算法讲起,随 ...