JavaScript的execCommand指令集

  1. /*  
  2. *该function执行copy指令  
  3. */  
  4. function fn_doufucopy(){   
  5. edit.select();   
  6. document.execCommand('Copy');   
  7. }   
  8. /*  
  9. *该function执行paste指令  
  10. */  
  11. function fn_doufupaste() {    
  12. tt.focus();   
  13. document.execCommand('paste');   
  14. }    
  15. /*  
  16. *该function用来创建一个超链接  
  17. */  
  18. function fn_creatlink()   
  19. {   
  20.   document.execCommand('CreateLink',true,'true');//弹出一个对话框输入URL   
  21.   //document.execCommand('CreateLink',false,'http://www.51js.com');   
  22. }   
  23. /*  
  24. *该function用来将选中的区块设为指定的背景色  
  25. */  
  26. function fn_change_backcolor()   
  27. {   
  28.   document.execCommand('BackColor',true,'#FFbbDD');//true或false都可以   
  29. }   
  30. /*  
  31. *该function用来将选中的区块设为指定的前景色,改变选中区块的字体大小,改变字体,字体变粗变斜  
  32. */  
  33. function fn_change_forecolor()   
  34. {   
  35. //指定前景色   
  36. document.execCommand('ForeColor',false,'#BBDDCC');//true或false都可以   
  37. //指定背景色   
  38. document.execCommand('FontSize',false,7);   //true或false都可以   
  39. //字体必须是系统支持的字体   
  40. document.execCommand('FontName',false,'标楷体');   //true或false都可以   
  41. //字体变粗   
  42. document.execCommand('Bold');   
  43. //变斜体   
  44. document.execCommand('Italic');   
  45. }   
  46. /*  
  47. *该function用来将选中的区块加上不同的线条  
  48. */  
  49. function fn_change_selection()   
  50. {   
  51. //将选中的文字加下划线   
  52. document.execCommand('Underline');   
  53. //在选中的文字上划粗线   
  54. document.execCommand('StrikeThrough');   
  55. //将选中的部分文字变细   
  56. document.execCommand('SuperScript');   
  57. //将选中区块的下划线取消掉   
  58. document.execCommand('Underline');    
  59. }   
  60. /*  
  61.   *该function用来将选中的区块排成不同的格式  
  62.   */  
  63. function fn_format()   
  64. {   
  65. //有序列排列   
  66. document.execCommand('InsertOrderedList');   
  67. //实心无序列排列   
  68. document.execCommand('InsertUnorderedList');   
  69. //空心无序列排列   
  70. document.execCommand('Indent');   
  71. }   
  72. /*  
  73. *该function用来将选中的区块剪下或是删除掉  
  74. */  
  75. function fn_CutOrDel()   
  76. {   
  77. //删除选中的区块   
  78. //document.execCommand('Delete');   
  79. //剪下选中的区块   
  80. document.execCommand('Cut');   
  81. }   
  82. /*  
  83. *该function用来将选中的区块重设为一个相应的物件  
  84. */  
  85. function fn_InsObj()   
  86. {   
  87. /*  
  88.   ******************************************  
  89.   * 以下指令都是为选中的区块重设一个object;  
  90.   * 如没有特殊说明,第二个参数true或false是一样的;  
  91.   * 参数三表示为该object的id;  
  92.   * 可以用在javascript中通过其指定的id来控制它  
  93.   ******************************************  
  94. */  
  95. /*重设为一个button(InsertButton和InsertInputButtong一样,  
  96. 只不前者是button,后者是input)*/  
  97. /*document.execCommand('InsertButton',false,"aa"); //true或false无效  
  98. document.all.aa.value="风舞九天";*/  
  99. //重设为一个fieldset   
  100. /*document.execCommand('InsertFieldSet',true,"aa");  
  101. document.all.aa.innerText="刀剑如梦";*/  
  102. //插入一个水平线   
  103. //document.execCommand('InsertHorizontalRule',true,"aa");   
  104. //插入一个iframe   
  105. //document.execCommand('InsertIFrame',true,"aa");   
  106. //插入一个InsertImage,设为true时需要图片,false时不需图片   
  107. //document.execCommand('InsertImage',false,"aa");   
  108. //插入一个checkbox   
  109. //document.execCommand('InsertInputCheckbox',true,"aa");   
  110. //插入一个file类型的object   
  111. //document.execCommand('InsertInputFileUpload',false,"aa");   
  112. //插入一个hidden   
  113. /*document.execCommand('InsertInputHidden',false,"aa");  
  114. alert(document.all.aa.id);*/  
  115. //插入一个InputImage   
  116. /*document.execCommand('InsertInputImage',false,"aa");  
  117. document.all.aa.src="F-a10.gif";*/  
  118. //插入一个Password   
  119. //document.execCommand('InsertInputPassword',true,"aa");   
  120. //插入一个Radio   
  121. //document.execCommand('InsertInputRadio',false,"aa");   
  122. //插入一个Reset   
  123. //document.execCommand('InsertInputReset',true,"aa");   
  124. //插入一个Submit   
  125. //document.execCommand('InsertInputSubmit',false,"aa");   
  126. //插入一个input text   
  127. //document.execCommand('InsertInputText',false,"aa");   
  128. //插入一个textarea   
  129. //document.execCommand('InsertTextArea',true,"aa");   
  130. //插入一个 select list box   
  131. //document.execCommand('InsertSelectListbox',false,"aa");   
  132. //插入一个single select   
  133. //document.execCommand('InsertSelectDropdown',true,"aa");   
  134. //插入一个line break(硬回车??)   
  135. //document.execCommand('InsertParagraph');   
  136. //插入一个marquee   
  137. /*document.execCommand('InsertMarquee',true,"aa");  
  138. document.all.aa.innerText="bbbbb";*/  
  139. //用于取消选中的阴影部分   
  140. //document.execCommand('Unselect');   
  141. //选中页面上的所有元素   
  142. //document.execCommand('SelectAll');   
  143. }   
  144. /*  
  145. *该function用来将页面保存为一个文件  
  146. */  
  147. function fn_save()   
  148. {   
  149. //第二个参数为欲保存的文件名   
  150. document.execCommand('SaveAs','mycodes.txt');   
  151. //打印整个页面   
  152. //document.execCommand('print');   
原文地址:https://www.cnblogs.com/top5/p/2097809.html