这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
deleteFromDocument()
方法在
Selection
interface deletes the selected text from the document's DOM.
sel.deleteFromDocument()
None.
This example lets you delete selected text by clicking a button. Upon clicking the button, the
Window.getSelection()
method gets the selected text, and the
deleteFromDocument()
method removes it.
<p>Try highlighting some of the text in this paragraph. Once you do, you can remove the selected content by clicking the button below.</p> <button>Delete selected text</button>
let button = document.querySelector('button');
button.addEventListener('click', deleteSelection);
function deleteSelection() {
let selection = window.getSelection();
selection.deleteFromDocument();
}
| 规范 | 状态 | 注释 |
|---|---|---|
|
选定 API
The definition of 'Selection.deleteFromDocument()' in that specification. |
工作草案 | Current |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
deleteFromDocument
|
Chrome Yes | Edge 12 | Firefox 55 | IE ? | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 55 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
兼容性未知
实验。期望将来行为有所改变。
Selection
, the interface defining this method
Selection
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
Document
DocumentFragment
DocumentType
元素
ElementTraversal
Entity
EntityReference
事件
EventTarget
HTMLCollection
MutationObserver
节点
NodeFilter
NodeIterator
NodeList
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
范围
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TreeWalker
TypeInfo
USVString
UserDataHandler
XMLDocument