1

在滚动包装器 div 时,我需要不同的嵌套子级来做不同的事情。

一个 div 需要淡化到一个不透明度级别,另一个 div 需要做另一件事。

这一切都包裹在很多我无法篡改的东西中。

我不知道如何在儿童中称呼儿童....我已经尝试了 jQuery 的每一个 frikkin 组合,但它就是不想玩,因为它与函数的“this”部分挂钩。

但是,如果我去掉“this”,它会对文档中的所有实例执行操作。

<div class="vpMedia"><li><a href="http://site.com"><div class="vpArrow"><image src="http://site.com/image1"></div><div class="vpLeft">Title</div><div class="vpRight">
<div class="vpRightImg"><image src="http://site.com/image2"></div></div></a></li></div>

我到处搜索与在孩子中寻找孩子有关的问题或主题,但唉,周围真的什么都没有。我没有看到类似的东西:

this.children(.foo).children(#bar)

或者也许走这条路?

this > .foo > #bar

因为它永远不会起作用,所以“this”需要在引号之外。那么如果我们不能使用 em,解决方案是什么?

编辑 - 好的,所以这是一个非常新手的问题。抱歉,希望能帮助某个地方的初学者。谢谢你的耐心。

4

4 回答 4

2

试过$(".foo>#bar", this)还是$(this).children('.foo').children('#bar')

另外,请记住,合法的 ID 在一个页面中应该是唯一的,所以这个例子可以写成$('#bar')......

于 2010-07-28T18:10:10.990 回答
2

你需要做.children('.vpLeft')的,不是.children('vpLeft')。您正在选择一个其 nodeName === 'vpLeft' 的元素。

$("div .vpMedia").mouseover(function() {
    $(this).children("li").children("a").children(".vpLeft").animate({opacity: .3}, { duration: 100, queue: false });
}).mouseout(function() {
    $(this).children("li").children("a").children(".vpLeft").animate({opacity: 1}, { duration: 100, queue: false });
})

可以缩短。。

$("div .vpMedia").mouseover(function() {
    $('>li>a>.vpLeft', this).animate({opacity: .3}, { duration: 100, queue: false });
}).mouseout(function() {
    $('>li>a>.vpLeft', this).animate({opacity: 1}, { duration: 100, queue: false });
})

<img>也不是<image>

于 2010-07-28T18:30:32.990 回答
1

要调用孩子的孩子,您可以这样做:

$(this).children(".foo").children("#bar");

或者您可以使用find类似于children递归扫描 DOM 的方法。

$(this).find("#bar");
于 2010-07-28T18:09:22.397 回答
0

我相信 $(this).find() 会为此工作。

查看http://api.jquery.com/find/了解有关查找的更多信息。

于 2010-07-28T18:08:55.420 回答