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

Jay*_*Dee 2 javascript jquery

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

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

我的代码到目前为止:

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

$(".paraContent").each(function(index[excContent]) {
    $(this).hide();
})
Run Code Online (Sandbox Code Playgroud)

Den*_*ret 5

如果我理解你正在尝试做什么,那就是隐藏一些paraContent基于索引的类的元素,你可以做到

$.each(excContent, function(){$('.paraContent:eq('+this+')').hide()});
Run Code Online (Sandbox Code Playgroud)

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

var $all = $('.paraContent');
$.each(excContent, function(){$all.eq(this).hide()});
Run Code Online (Sandbox Code Playgroud)