gpt4 book ai didi

javascript - js 函数不在 IE 8 中的数组元素中运行

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

当我尝试执行此代码时:

$('.pagination-item')[$('.blog-item:visible').index()].addClass("active");

在 IE8 中出现以下消息:

object doesn't support property or method 'addclass'

实际上,甚至 .hide() 或 .show() 都不能再次执行 $('.pagination-item')[0]。我怀疑IE8中的数组元素管理有问题。你有任何线索吗?为什么会出现这个错误?

最佳答案

$('.pagination-item')[$('.blog-item:visible').index()] 返回一个 dom 对象引用,而不是 jQuery 包装对象,因此它返回没有 addClass 方法。

您可以使用.eq()

$('.pagination-item').eq($('.blog-item:visible').index()).addClass("active");

关于javascript - js 函数不在 IE 8 中的数组元素中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18592577/

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