gpt4 book ai didi

javascript - jQuery.each() 未定义问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:06:14 26 4
gpt4 key购买 nike

我有以下代码

function myFunction(items) {
// this prints out 11
alert(items.length);

$(items).each(function(i, item) {
// item is undefined for some reason
}
}

我提醒项目的长度,其中包含元素(准确地说是 11 个)。那么 11 个项目怎么可能存在,但 jQuery 仍然通过未定义?

最佳答案

对此的唯一解释是 items 数组包含未定义的值,即:

items = [undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined];

其他两个答案都是完全错误的。 each的第一个参数是索引,不是值,jQuery.fn.each调用的是jQuery.each。它们之间没有歧义。

关于javascript - jQuery.each() 未定义问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3330264/

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