cut
event is fired when the user has initiated a "cut" action through the browser's user interface.
If the user attempts a cut action on uneditable content, the
cut
event still fires but the event object contains no data.
| 冒泡 | Yes |
|---|---|
| 可取消 | Yes |
| 接口 |
ClipboardEvent
|
| 事件处理程序特性 |
oncut
|
The event's default action is to copy the current selection (if any) to the system clipboard and remove it from the document.
A handler for this event can
修改
the clipboard contents by calling
setData(format, data)
on the event's
ClipboardEvent.clipboardData
property, and cancelling the default action using
event.preventDefault()
.
Note though that cancelling the default action will also prevent the document from being updated. So an event handler which wants to emulate the default action for "cut" while modifying the clipboard must also manually remove the selection from the document.
The handler cannot read the clipboard data.
It's possible to construct and dispatch a
synthetic
cut
event, but this will not affect the system clipboard or the document's contents.
<div class="source" contenteditable="true">Try cutting text from this box...</div> <div class="target" contenteditable="true">...and pasting it into this one</div>
div.source, div.target {
border: 1px solid gray;
margin: .5rem;
padding: .5rem;
height: 1rem;
background-color: #e9eef1;
}
const source = document.querySelector('div.source');
source.addEventListener('cut', (event) => {
const selection = document.getSelection();
event.clipboardData.setData('text/plain', selection.toString().toUpperCase());
selection.deleteFromDocument();
event.preventDefault();
});
| 规范 | 状态 |
|---|---|
| Clipboard API and events | 工作草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
cut
event
|
Chrome 58 | Edge ≤18 | Firefox Yes | IE Yes | Opera 45 | Safari Yes | WebView Android 58 | Chrome Android 58 | Firefox Android Yes | Opera Android 43 | Safari iOS Yes | Samsung Internet Android 7.0 |
clipboardData
|
Chrome 58 | Edge ≤18 | Firefox 22 | IE No | Opera 45 | Safari Yes | WebView Android 58 | Chrome Android 58 | Firefox Android 22 | Opera Android 43 | Safari iOS Yes | Samsung Internet Android 7.0 |
完整支持
不支持
元素
accessKey
属性
childElementCount
children
classList
className
clientHeight
clientLeft
clientTop
clientWidth
currentStyle
firstElementChild
id
innerHTML
lastElementChild
localName
名称
namespaceURI
nextElementSibling
onfullscreenchange
onfullscreenerror
openOrClosedShadowRoot
outerHTML
part
prefix
previousElementSibling
runtimeStyle
scrollHeight
scrollLeft
scrollLeftMax
scrollTop
scrollTopMax
scrollWidth
shadowRoot
slot
tabStop
tagName
after()
animate()
append()
attachShadow()
before()
closest()
computedStyleMap()
createShadowRoot()
getAnimations()
getAttribute()
getAttributeNames()
getAttributeNode()
getAttributeNodeNS()
getAttributeNS()
getBoundingClientRect()
getClientRects()
getElementsByClassName()
getElementsByTagName()
getElementsByTagNameNS()
hasAttribute()
hasAttributeNS()
hasAttributes()
hasPointerCapture()
insertAdjacentElement()
insertAdjacentHTML()
insertAdjacentText()
matches()
msZoomTo()
prepend()
querySelector()
querySelector()
querySelectorAll()
querySelectorAll()
releasePointerCapture()
remove()
removeAttribute()
removeAttributeNode()
removeAttributeNS()
replaceChildren()
replaceWith()
requestFullscreen()
requestPointerLock()
scroll()
scrollBy()
scrollIntoView()
scrollIntoViewIfNeeded()
scrollTo()
setAttribute()
setAttributeNode()
setAttributeNodeNS()
setAttributeNS()
setCapture()
setPointerCapture()
toggleAttribute()
afterscriptexecute
auxclick
blur
click
compositionend
compositionstart
compositionupdate
contextmenu
copy
cut
dblclick
DOMActivate
DOMMouseScroll
error
focus
focusin
focusout
fullscreenchange
fullscreenerror
gesturechange
gestureend
gesturestart
keydown
keypress
keyup
mousedown
mouseenter
mouseleave
mousemove
mouseout
mouseover
mouseup
mousewheel
MozMousePixelScroll
msContentZoom
MSGestureChange
MSGestureEnd
MSGestureHold
MSGestureStart
MSGestureTap
MSInertiaStart
MSManipulationStateChanged
overflow
paste
scroll
select
show
touchcancel
touchend
touchmove
touchstart
underflow
webkitmouseforcechanged
webkitmouseforcedown
webkitmouseforceup
webkitmouseforcewillbegin
wheel