Javascript 如何";增强;使用$进行jQuery搜索(这是什么)?

Javascript 如何";增强;使用$进行jQuery搜索(这是什么)?,javascript,jquery,Javascript,Jquery,我在绕着某个部门的孩子转 根据孩子们是奇数还是偶数,我有不同的以下操作 我想使用jQuery的$(this)获取当前上下文,并根据其奇数或偶数状态添加到查询中 如果它是偶数子对象,我希望得到该div的子对象(因此这是循环中的子对象的子对象)。我该怎么做 我目前的方法不起作用 $("div.profile_result").children().each(function(a){ // This way of adding the child a doesn't work if (a%2) con

我在绕着某个部门的孩子转

根据孩子们是奇数还是偶数,我有不同的以下操作

我想使用jQuery的$(this)获取当前上下文,并根据其奇数或偶数状态添加到查询中

如果它是偶数子对象,我希望得到该div的子对象(因此这是循环中的子对象的子对象)。我该怎么做

我目前的方法不起作用

$("div.profile_result").children().each(function(a){
// This way of adding the child a doesn't work
if (a%2) console.log( $($(this) + " > a"))


else console.log("info")
})
可以使用$(this).index()确定它是奇数还是偶数

$("div.profile_result").children().each(function(a){
// This way of adding the child a doesn't work
var el = $(this);
var el_index = el.index();//node the index starts from 0;
if ((el_index+1)%2 == 0)
  console.log( el.children() ); // this is even
else 
  console.log("info");
});
$($(this)+>a”)
正在尝试连接一个对象和一个字符串,这是您无法做到的


使用
$(this)。改为查找('a')

让我们看看HTML,当你说奇数或偶数时,你是指数字还是索引?问题在于
$($(this)+>a”)
部分。我有奇数和偶数的功能。听起来你想选择
$('div.profile\u result>:even>a')
。是的,那会有用的。如果我使用两个.each()方法,我可以这样做
a
已经是索引了。为什么要返回dom以获取每个
已经提供的内容?OP的问题与获取索引值无关