gpt4 book ai didi

jquery - preloadImages() 函数出错

转载 作者:行者123 更新时间:2023-12-01 05:37:57 26 4
gpt4 key购买 nike

我有这个 javascript 函数来预加载图像:

function preloadImages() {
var images = [];

function preload() {
for(var i = 0; i < preload.arguments.list; i++) {
images[i] = new Image();
images[i].src = preload.arguments[i];
}
}

preload(
"../img/innovation_1_hover.jpg",
"../img/innovation_2_hover.jpg",
"../img/innovation_3_hover.jpg",
"../img/innovation_4_hover.jpg",
"../img/innovation_5_hover.jpg"
);
}
preloadImages();

但我收到错误:

Uncaught TypeError: 'caller' and 'arguments' are restricted function properties and cannot be accessed in this context.

enter image description here

怎么了?我该如何修复它?作为引用,我使用 Chrome。

最佳答案

更换您的

preload.arguments.list
with
arguments.length

function preloadImages() 
{
var images = [];
function preload()
{

for(var i = 0; i <arguments.length; i++)
{

images[i] = new Image();
images[i].src = preload.arguments[i];
console.log(images[i]); // for testing
}
}
preload(
"../img/innovation_1_hover.jpg",
"../img/innovation_2_hover.jpg",
"../img/innovation_3_hover.jpg",
"../img/innovation_4_hover.jpg",
"../img/innovation_5_hover.jpg"
);
}
preloadImages();

关于jquery - preloadImages() 函数出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32736665/

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