HTML DOM Document execCommand() 方法

定義和用法

execCommand() 方法已棄用。請勿使用它。

applet 屬性在所有新瀏覽器中返回空的 HTMLCollection

HTML5 不支持 <applet> 元素。

備選方案:

Document designMode 屬性

Element contentEditable 屬性

實例

使選定的文本加粗:

document.execCommand("bold");

親自試一試

語法

document.execCommand(command, showUI, value)

參數

參數 描述
command

要執行的命令的名稱:

  • "backColor"
  • "bold"
  • "createLink"
  • "copy"
  • "cut"
  • "defaultParagraphSeparator"
  • "delete"
  • "fontName"
  • "fontSize"
  • "foreColor"
  • "formatBlock"
  • "forwardDelete"
  • "insertHorizontalRule"
  • "insertHTML"
  • "insertImage"
  • "insertLineBreak"
  • "insertOrderedList"
  • "insertParagraph"
  • "insertText"
  • "insertUnorderedList"
  • "justifyCenter"
  • "justifyFull"
  • "justifyLeft"
  • "justifyRight"
  • "outdent"
  • "paste"
  • "redo"
  • "selectAll"
  • "strikethrough"
  • "styleWithCss"
  • "subscript"
  • "superscript"
  • "undo"
  • "unlink"
  • "useCSS"
showUI 布爾值。指定是否應顯示 UI。
value 有些命令需要值才能完成。

返回值

類型 描述
布爾值 如果支持該命令,則為 true,否則為 false。