HTMLElement:cut 事件
Invalid slug for templ/sidebar: conflicting/Web/API/Element/cut_event_8c227abc15b3d636603d3c5d69c859e14ecff3bdc3c5c34f2106a7e7bc7f98e0
cut
事件在用户通过浏览器的用户界面开始剪切操作时触发。
语法
在类似 addEventListener()
这样的方法中使用事件名称,或设置事件处理器属性。
js
addEventListener("cut", (event) => {});
oncut = (event) => {};
事件类型
ClipboardEvent
。继承自 Event
。
事件属性
也从其父接口 Event
继承属性。
ClipboardEvent.clipboardData
只读-
一个
DataTransfer
对象,其包含用户发起的cut
、copy
或paste
操作所影响的数据,以及它的 MIME 类型。
示例
此示例允许从 <textarea>
复制文本,但不允许剪切文本。它还记录每次复制和剪切的尝试。
HTML
html
<h3>试一下这个文本区域:</h3>
<textarea id="editor" rows="3">
尝试复制和剪切该字段中的文本!
</textarea>
<h3>日志:</h3>
<p id="log"></p>
JavaScript
js
function logCopy(event) {
log.innerText = `已复制!\n${log.innerText}`;
}
function preventCut(event) {
event.preventDefault();
log.innerText = `已阻止剪切!\n${log.innerText}`;
}
const editor = document.getElementById("editor");
const log = document.getElementById("log");
editor.oncopy = logCopy;
editor.oncut = preventCut;
结果
规范
No specification found
No specification data found for undefined
.
Check for problems with this page or contribute a missing spec_url
to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.