剪贴板事件 [英] Clipboard Event
问题描述
我在从代码创建 ClipboardEvent 时遇到了问题.未定义创建事件中的 clipboardData 对象.
可能有人对此有所了解吗?
<html lang="zh-cn"><头><meta charset="UTF-8"><title>文档</title>头部><身体><input id="testPasteInput"><button onclick="pasteFromCode()">粘贴</button><脚本>const testPasteInput = document.getElementById('testPasteInput');testPasteInput.addEventListener('paste', ({clipboardData}) => console.log(clipboardData.getData('text')));函数 pasteFromCode() {const clipboardEvent = new ClipboardEvent('paste', { dataType: 'text/plain', data: '123' });testPasteInput.dispatchEvent(clipboardEvent);}