我正在寻找一些东西,使我能够单独控制 .prevAll() 或 .nextAll() jQuery 方法返回的每个元素。
类似于:
<div id="home">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
还有类似的东西:
$('#home .box').mouseover(function(){
var hovBox = $(this);
var prevAll = hovBox.prevAll();
var nextAll = hovBox.nextAll();
nextAll.each(function(){
// ...and do something with each returned element
// NOT with ALL returned elements, just handle each separately
// through some other type of selector
});
});
感谢您的帮助
最佳答案
$.each 允许您使用 this
访问 DOM 元素:
nextAll.each(function(index){
// ...and do something with each returned element
$(this).fadeTo('fast', index/5);
});
这是 fiddle : http://jsfiddle.net/2MMGw/1/
关于jquery - 如何分别处理 .nextAll() 或 .prevAll() - 每个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6940780/