相关疑难解决方法(0)

剪贴板事件

我在从代码创建 ClipboardEvent 时遇到了问题。未定义创建事件中的 clipboardData 对象。

可能有人对此有所了解?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <input id="testPasteInput">
    <button onclick="pasteFromCode()">Paste</button>
    <script>
        const testPasteInput = document.getElementById('testPasteInput');
        testPasteInput.addEventListener('paste', ({clipboardData}) => console.log(clipboardData.getData('text')));

        function pasteFromCode() {
            const clipboardEvent = new ClipboardEvent('paste', { dataType: 'text/plain', data: '123' });
            testPasteInput.dispatchEvent(clipboardEvent);
        }
    </script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

html javascript

5
推荐指数
1
解决办法
2474
查看次数

标签 统计

html ×1

javascript ×1