日期:2014-05-16 浏览次数:20423 次
<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_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="B