<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 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)>
<HTML>
<HEAD>
<TITLE>JavaScript--execCommand指令集</TITLE>
 <SCRIPT LANGUAGE="javascript">
<!--
 /**//*該function執(zhí)行copy指令*/
function fn_doufucopy()
 {edit.select();
document.execCommand('Copy');
}

 /**//*該function執(zhí)行paste指令*/
function fn_doufupaste()
 { tt.focus();
document.execCommand('paste');
}


 /**//**該function用來創(chuàng)建一個超鏈接*/
function fn_creatlink()
 { document.execCommand('CreateLink',true,'true'); //彈出一個對話框輸入URL//
document.execCommand('CreateLink',false,'http://www.51js.com');
}


 /**//**該function用來將選中的區(qū)塊設(shè)為指定的背景色*/
 function fn_change_backcolor() {
document.execCommand('BackColor',true,'#FFbbDD');//true或false都可以
}
 /**//**該function用來將選中的區(qū)塊設(shè)為指定的前景色,改變選中區(qū)塊的字體大小,改變字體,字體變粗變斜*/
 function fn_change_forecolor() {
//指定前景色
document.execCommand('ForeColor',false,'#BBDDCC');//true或false都可以
//指定背景色
document.execCommand('FontSize',false,7); //true或false都可以
//字體必須是系統(tǒng)支持的字體
document.execCommand('FontName',false,'標(biāo)楷體'); //true或false都可以
//字體變粗
document.execCommand('Bold');
//變斜體
document.execCommand('Italic');}
 /**//**該function用來將選中的區(qū)塊加上不同的線條*/
 function fn_change_selection() {
//將選中的文字加下劃線
document.execCommand('Underline');
//在選中的文字上劃粗線
document.execCommand('StrikeThrough');
//將選中的部分文字變細(xì)
document.execCommand('SuperScript');
//將選中區(qū)塊的下劃線取消掉
document.execCommand('Underline'); }
 /**//**該function用來將選中的區(qū)塊排成不同的格式*/
 function fn_format() {
//有序列排列
document.execCommand('InsertOrderedList');
//實心無序列排列
document.execCommand('InsertUnorderedList');
//空心無序列排列
document.execCommand('Indent');
}



 /**//**該function用來將選中的區(qū)塊剪下或是刪除掉*/
 function fn_CutOrDel() {
//刪除選中的區(qū)塊//
document.execCommand('Delete');
//剪下選中的區(qū)塊
document.execCommand('Cut');}


 /**//**該function用來將頁面保存為一個文件*/
 function fn_save() {
//第二個參數(shù)為欲保存的文件名
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> 都怪我,太執(zhí)著,卻也等不到花開葉落.<br> <br> Please select above letters, then click following buttons:<br> <hr>
<input type="button" value="創(chuàng)建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>
|