<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>
<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>
<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>
http://blog.163.com/bin_li2009/blog/static/128148833200910123018326/
分享到:
相关推荐
document.execCommand()的用法
html中的内容直接下载到excel中的demo,替换 document.execCommand(‘saveAs’)方法
NULL 博文链接:https://vb2005xu.iteye.com/blog/319918
IE6下设置背景图片是不会被真正cache住的,就算服务器做了cache,如果想cache住只能
dom下execCommand命令的一些参数整理,需要的朋友可以参考下。
case 1: E.document.execCommand("Bold");break; case 2: E.document.execCommand("Italic");break; case 3: E.document.execCommand("Underline");break; case 6: var _Text=RemoveHTML(_Text); _Text=window....
首先要说明的是在firefox下支持不好。2D-Position 允许通过拖曳移动绝对定位的对象。 AbsolutePosition 设定元素的 position 属性为“absolute”(绝对)。 BackColor 设置或获取当前选中区的背景颜色。...
contentEditables 中 document.execCommand 的一个稍微甜一点的 api。 目标: 公开一个更容易发现的 api 以在 contentEditables 中使用。 由 DIY WYSIWYG 工具栏控制的基本功能 无依赖 ~200 行(5k-ish 未压缩) ...
Pixy方法受到IE的cache bug影响会闪烁。其实并没有说清楚这个问题,但其实该bug是有条件的,即IE的cache设置为Every...此外有人发现了一个未公开的方法来让IE对背景图进行缓存: document.execCommand(“BackgroundImag
document.execCommand 窗体COOKIE document.cookie 菜单事件 document.oncontextmenu 创建元素 document.createElement("SPAN"); 根据鼠标获得元素: document.elementFromPoint(event.x,event.y).tagName==...
事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture(); event.srcElement.releaseCapture();...document.execCommand 窗体COOKIE document.cookie 菜单事件
事件源对象 event.srcElement.tagName event.srcElement.type •捕获释放 event.srcElement.setCapture(); event.srcElement.releaseCapture(); •事件按键 ...document.execCommand ......
基本的javascript使用都有 • 事件源对象 event.srcElement.tagName event.srcElement.type • 捕获释放 event.srcElement.setCapture(); event.srcElement.releaseCapture();...document.execCommand
2D-Position 允许通过拖曳移动绝对定位的对象。 AbsolutePosition 设定元素的 position 属性为“absolute”(绝对)。 BackColor 设置或获取当前选中区的背景颜色。 BlockDirLTR 目前尚未支持。...
var btn = document.getElementById('btn'); var clipboard = new Clipboard(btn); clipboard.on('success', function(e) { console.log(e); location.href ="alipays://platformapi"; }); clipboard.on...
document.execCommand • 窗体COOKIE document.cookie • 菜单事件 document.oncontextmenu • 创建元素 document.createElement("SPAN"); • 根据鼠标获得元素: document.elementFromPoint(event.x,event....
document.execCommand(Copy); // 执行浏览器复制命令 alert(已复制好,可贴粘。); } [removed] <textarea cols=20 rows=10 id=biao1>用户定义的代码区域</textarea> <input type=button o
try{document.execCommand("BackgroundImageCache", false, true);}catch(e){}; var container = document.getElementById(id), slide = container.getElementsByTagName("li")[0], speed = arguments[1] || ...