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。