gpt4 book ai didi

javascript - ClipboardData - 未捕获类型错误 : Cannot read property 'length' of undefined

转载 作者:行者123 更新时间:2023-11-28 01:59:20 25 4
gpt4 key购买 nike

这是抛出错误的代码,不知道为什么,它曾经与 Chrome 一起使用。我现在使用 Chromium,它抛出错误 Uncaught TypeError: Cannot read property 'length' of undefined

$wnd.addEventListener("paste",processEvent);
function processEvent(e) {
if (e.clipboardData && e.clipboardData.getData) {
console.log("clipboard from event"); // can see in console log
var items = e.clipboardData.items;
if(items.length == 0){ // error here

}
}
}

看来问题是 var items 未定义

最佳答案

我会检查items是否首先被定义

$wnd.addEventListener("paste",processEvent);

    function processEvent(e) {

if (e.clipboardData && e.clipboardData.getData) {

console.log("clipboard from event"); // can see in console log
var items = e.clipboardData.items;
if(items != undefined && items.length == 0){ // error here

}
}
}

但是你cannot read or set clip board data in JavaScript

关于javascript - ClipboardData - 未捕获类型错误 : Cannot read property 'length' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18669487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com