我們的志工尚未將本文翻譯為 正體中文 (繁體) 版本。加入我們,幫忙翻譯!
您也可以閱讀本文的 English (US) 版本。

Non-standard
This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The HTMLElement.oncut property returns the onCut event handler code on the current element. This event is sent when the user attempts to cut text.

Syntax

element.oncut = functionRef;

where functionRef is a function - often a name of a function declared elsewhere or a function expression. See Core JavaScript 1.5 Reference:Functions for details.

Example

This example allows text to be copied from the textarea, but doesn't allow text to be cut. It also logs each copy and cut attempt to a <textarea>.

HTML

<h3>Play with this text area:</h3>
<textarea id="editor" rows="3" cols="60" oncopy="log('Copied!');" oncut="log('Cut blocked!'); return false;">
Try copying and cutting the text in this area!
</textarea>

<h3>Log:</h3>
<textarea id="log" rows="15" cols="60" readonly></textarea>

CSS

function log(text) {
  const log = document.getElementById('log');
  log.appendChild(document.createTextNode(text + '\n'));
}

Result

Specification

Not part of any specification. See the W3C Working Draft at cut.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic support
Non-standard
Chrome ? Edge Full support YesFirefox Full support 3IE ? Opera ? Safari ? WebView Android ? Chrome Android ? Edge Mobile Full support YesFirefox Android Full support 4Opera Android ? Safari iOS ? Samsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.

Since Firefox 13, the preference dom.event.clipboardevents.enabled controls this feature. It defaults to true but can be disabled.

See also

文件標籤與貢獻者

最近更新: mfluehr,