我有一个节点列表:
<div id="node-1"></div>
<div id="node-2" class="current"></div>
<div id="node-3"></div>
<div id="node-4"></div>
<div id="node-5"></div>当使用$(".current")作为选择器(node-2)时,我如何使用get获取所有节点3-5?
发布于 2012-05-25 19:23:18
在Zepto.js中有类似nextAll()的东西吗?
the documentation并非如此,它在next之后和not之前有一个明显的差距。
这表明你需要一个循环,例如:
var $current = $(".current"),
$walk,
$following = $(),
$next;
for ($walk = $current.next(); $walk[0]; $walk = $walk.next()) {
$following.add($walk);
}在jQuery中使用add就可以了。Zepto的文档声称“提供的API与它们的jQuery API(粗体)相匹配,但add docs只谈到了使用选择器,所以你可能不得不尝试一下。”
发布于 2012-09-20 07:30:06
这应该是可行的。就像http://api.jquery.com/nextAll/和http://api.jquery.com/prevAll/一样
;(function($){
var e = {
nextAll: function(s) {
var $els = $(), $el = this.next()
while( $el.length ) {
if(typeof s === 'undefined' || $el.is(s)) $els = $els.add($el)
$el = $el.next()
}
return $els
},
prevAll: function(s) {
var $els = $(), $el = this.prev()
while( $el.length ) {
if(typeof s === 'undefined' || $el.is(s)) $els = $els.add($el)
$el = $el.prev()
}
return $els
}
}
$.extend( $.fn, e )
})(Zepto);https://stackoverflow.com/questions/10753464
复制相似问题