我在一个页面上有一个动态生成的 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/