gpt4 book ai didi

javascript - 在 jQuery/JS 中使用数组定位重复类中的特定元素

转载 作者:行者123 更新时间:2023-11-29 16:18:16 26 4
gpt4 key购买 nike

我在一个页面上有一个动态生成的 HTML 部分,其中包含许多类为 <div class="paraContent"> 的重复元素。

我可以访问 <head> CMS 中的此页面,并希望在数组或脚本中指定元素以隐藏某些元素。

到目前为止我的代码:

var excContent = ['0', '1', '25']

$(".paraContent").each(function(index[excContent]) {
$(this).hide();
})

最佳答案

如果我明白你想做什么,那就是根据索引隐藏一些具有 paraContent 类的元素,你可以这样做

$.each(excContent, function(){$('.paraContent:eq('+this+')').hide()});

或者(如果你有一个大阵列更快):

var $all = $('.paraContent');
$.each(excContent, function(){$all.eq(this).hide()});

关于javascript - 在 jQuery/JS 中使用数组定位重复类中的特定元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13249378/

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