过时
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.
When an HTML document has been switched to
designMode
, its
document
object exposes an
execCommand
method to run commands that manipulate the current editable region, such as
form inputs
or
contentEditable
元素。
Most commands affect the document's
selection
(bold, italics, etc.), while others insert new elements (adding a link), or affect an entire line (indenting). When using
contentEditable
,
execCommand()
affects the currently active editable element.
document.execCommand(aCommandName, aShowDefaultUI, aValueArgument)
A
布尔
也就是
false
if the command is unsupported or disabled.
注意
: Only returns
true
if part of a user interaction. Don't try using the return value to verify browser support before calling a command.
aCommandName
DOMString
specifying the name of the command to execute. See
命令
for a list of possible commands.
aShowDefaultUI
布尔
indicating whether the default user interface should be shown. This is not implemented in Mozilla.
aValueArgument
DOMString
providing that information. For example,
insertImage
requires the URL of the image to insert. Specify
null
if no argument is needed.
backColor
styleWithCss
mode, it affects the background color of the containing block instead. This requires a
<color>
value string to be passed in as a value argument. Note that Internet Explorer uses this to set the text background color.
bold
<strong>
tag instead of
<b>
.
ClearAuthenticationCache
Clears all authentication credentials from the cache.
contentReadOnly
Makes the content document either read-only or editable. This requires a boolean true/false as the value argument. (Not supported by Internet Explorer.)
copy
Copies the current selection to the clipboard. Conditions of having this behavior enabled vary from one browser to another, and have evolved over time. Check the compatibility table to determine if you can use it in your case.
createLink
href
. The URI must contain at least a single character, which may be whitespace. (Internet Explorer will create a link with a
null
value.)
cut
decreaseFontSize
<small>
tag around the selection or at the insertion point. (Not supported by Internet Explorer.)
defaultParagraphSeparator
delete
删除当前选定。
enableAbsolutePositionEditor
enableInlineTableEditing
enableObjectResizing
fontName
"Arial"
) as a value argument.
fontSize
1
-
7
as a value argument.
foreColor
Changes a font color for the selection or at the insertion point. This requires a hexadecimal color value string as a value argument.
formatBlock
<blockquote>
is the exception — it will wrap any containing block element). Requires a tag-name string as a value argument. Virtually all block-level elements can be used. (Internet Explorer and Edge support only heading tags
H1
–
H6
,
ADDRESS
,和
PRE
, which must be wrapped in angle brackets, such as
"<H1>"
)。
forwardDelete
heading
"H1"
,
"H6"
). (Not supported by Internet Explorer and Safari.)
hiliteColor
useCSS
必须为
true
for this to function. (Not supported by Internet Explorer.)
increaseFontSize
<big>
tag around the selection or at the insertion point. (Not supported by Internet Explorer.)
indent
Indents the line containing the selection or insertion point. In Firefox, if the selection spans multiple lines at different levels of indentation, only the least indented lines in the selection will be indented.
insertBrOnReturn
<br>
element, or splits the current block element into two. (Not supported by Internet Explorer.)
insertHorizontalRule
<hr>
element at the insertion point, or replaces the selection with it.
insertHTML
Inserts an HTML string at the insertion point (deletes selection). Requires a valid HTML string as a value argument. (Not supported by Internet Explorer.)
insertImage
src
as a value argument. The requirements for this string are the same as
createLink
.
insertOrderedList
insertUnorderedList
insertParagraph
insertText
Inserts the given plain text at the insertion point (deletes selection).
italic
<em>
element instead of
<i>
)。
justifyCenter
Centers the selection or insertion point.
justifyFull
Justifies the selection or insertion point.
justifyLeft
Justifies the selection or insertion point to the left.
justifyRight
Right-justifies the selection or the insertion point.
outdent
Outdents the line containing the selection or insertion point.
paste
Pastes the clipboard contents at the insertion point (replaces current selection). Disabled for web content.
redo
Redoes the previous undo command.
removeFormat
Removes all formatting from the current selection.
selectAll
Selects all of the content of the editable region.
strikeThrough
Toggles strikethrough on/off for the selection or at the insertion point.
subscript
superscript
underline
undo
Undoes the last executed command.
unlink
useCSS
Toggles the use of HTML tags or CSS for the generated markup. Requires a boolean true/false as a value argument.
false
to use CSS,
true
to use HTML) and unsupported by Internet Explorer. This has been deprecated in favor of
styleWithCSS
.
styleWithCSS
useCSS
命令。
true
modifies/generates
style
attributes in markup, false generates presentational elements.
An example of how to use it on CodePen.
| 规范 | 状态 | 注释 |
|---|---|---|
| execCommand | 非官方草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
execCommand
弃用
非标
|
Chrome 1 | Edge 12 | Firefox 1 | IE 4 | Opera 9 | Safari 1.3 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 |
ClearAuthenticationCache
命令
弃用
非标
|
Chrome No | Edge 12 — 79 | Firefox No | IE 6 | Opera No | Safari No | WebView Android No | Chrome Android No | Firefox Android No | Opera Android No | Safari iOS No | Samsung Internet Android No |
copy
命令
弃用
非标
|
Chrome 42 | Edge 12 | Firefox 41 | IE 9 | Opera 29 | Safari 10 | WebView Android 42 | Chrome Android 42 | Firefox Android 41 | Opera Android 29 | Safari iOS 10 | Samsung Internet Android 4.0 |
cut
命令
弃用
非标
|
Chrome 42 | Edge 12 | Firefox 41 | IE 9 | Opera 29 | Safari 10 | WebView Android 42 | Chrome Android 42 | Firefox Android 41 | Opera Android 29 | Safari iOS 10 | Samsung Internet Android 4.0 |
defaultParagraphSeparator
命令
弃用
非标
|
Chrome No | Edge ≤18 — 79 | Firefox 55 | IE No | Opera Yes | Safari No | WebView Android No | Chrome Android No | Firefox Android 55 | Opera Android Yes | Safari iOS No | Samsung Internet Android No |
insertBrOnReturn
命令
弃用
非标
|
Chrome No | Edge No | Firefox Yes | IE No | Opera No | Safari No | WebView Android No | Chrome Android No | Firefox Android Yes | Opera Android No | Safari iOS No | Samsung Internet Android No |
完整支持
不支持
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
HTMLElement.contentEditable
document.designMode
document.execCommand
.
Document
alinkColor
all
anchors
applets
bgColor
body
characterSet
childElementCount
children
compatMode
contentType
currentScript
defaultView
designMode
dir
doctype
documentElement
documentURI
documentURIObject
domain
domConfig
嵌入
fgColor
firstElementChild
forms
fullscreen
fullscreenEnabled
head
height
hidden
图像
实现
lastElementChild
lastModified
lastStyleSheetSet
linkColor
链接
location
mozSyntheticDocument
onabort
onafterscriptexecute
onanimationcancel
onanimationend
onanimationiteration
onauxclick
onbeforescriptexecute
onblur
oncancel
oncanplay
oncanplaythrough
onchange
onclick
onclose
oncontextmenu
oncuechange
ondblclick
ondurationchange
onended
onerror
onfocus
onformdata
onfullscreenchange
onfullscreenerror
ongotpointercapture
oninput
oninvalid
onkeydown
onkeypress
onkeyup
onload
onloadeddata
onloadedmetadata
onloadend
onloadstart
onlostpointercapture
onmousedown
onmouseenter
onmouseleave
onmousemove
onmouseout
onmouseover
onmouseup
onoffline
ononline
onpause
onplay
onplaying
onpointercancel
onpointerdown
onpointerenter
onpointerleave
onpointermove
onpointerout
onpointerover
onpointerup
onreset
onresize
onscroll
onselect
onselectionchange
onselectstart
onsubmit
ontouchcancel
ontouchstart
ontransitioncancel
ontransitionend
onvisibilitychange
onwheel
origin
plugins
popupNode
preferredStyleSheetSet
readyState
referrer
rootElement
脚本
scrollingElement
selectedStyleSheetSet
styleSheetSets
timeline
title
tooltipNode
URL
visibilityState
vlinkColor
width
xmlEncoding
xmlVersion
adoptNode()
append()
caretRangeFromPoint()
clear()
close()
createAttribute()
createCDATASection()
createComment()
createDocumentFragment()
createElement()
createElementNS()
createEntityReference()
createEvent()
createExpression()
createExpression()
createNodeIterator()
createNSResolver()
createNSResolver()
createProcessingInstruction()
createRange()
createTextNode()
createTouch()
createTouchList()
createTreeWalker()
enableStyleSheetsForSet()
evaluate()
evaluate()
execCommand()
exitFullscreen()
exitPointerLock()
getAnimations()
getBoxObjectFor()
getElementById()
getElementsByClassName()
getElementsByName()
getElementsByTagName()
getElementsByTagNameNS()
hasFocus()
hasStorageAccess()
importNode()
mozSetImageElement()
open()
prepend()
queryCommandEnabled()
queryCommandSupported()
querySelector()
querySelector()
querySelectorAll()
querySelectorAll()
registerElement()
releaseCapture()
replaceChildren()
requestStorageAccess()
write()
writeln()
animationcancel
animationend
animationiteration
animationstart
copy
cut
DOMContentLoaded
drag
dragend
dragenter
dragexit
dragleave
dragover
dragstart
drop
fullscreenchange
fullscreenerror
gotpointercapture
keydown
keypress
keyup
lostpointercapture
paste
pointercancel
pointerdown
pointerenter
pointerleave
pointerlockchange
pointerlockerror
pointermove
pointerout
pointerover
pointerup
readystatechange
scroll
selectionchange
selectstart
touchcancel
touchend
touchmove
touchstart
transitioncancel
transitionend
transitionrun
transitionstart
visibilitychange
wheel
AbortController
AbortSignal
AbstractRange
Attr
ByteString
CDATASection
CSSPrimitiveValue
CSSValue
CSSValueList
CharacterData
ChildNode
注释
CustomEvent
DOMConfiguration
DOMError
DOMErrorHandler
DOMException
DOMImplementation
DOMImplementationList
DOMImplementationRegistry
DOMImplementationSource
DOMLocator
DOMObject
DOMParser
DOMPoint
DOMPointInit
DOMPointReadOnly
DOMRect
DOMString
DOMTimeStamp
DOMTokenList
DOMUserData
DocumentFragment
DocumentType
元素
ElementTraversal
Entity
EntityReference
事件
EventTarget
HTMLCollection
MutationObserver
节点
NodeFilter
NodeIterator
NodeList
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
范围
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TreeWalker
TypeInfo
USVString
UserDataHandler
XMLDocument