2014-01-17 61 views

回答

6

作为一个通用的解决方案,以找到第二天元素

var idx = $('day.selected').index('day'), 
    $next = $('day').eq(idx + 1); 

演示(不考虑父元素):Fiddle,也see this

2

试试这个:

$('.selected').parent().next().find(':first-child') 
+0

如果所选的一天是不是最后一天在周? –

+0

@JasonP嗯,我只是根据OP的情况来回答。你可以使用Arun的答案:P – Felix

1

要处理所有可能出现的情况,这样的事情可以做:

var curDay = $('.selected'); 
var nextDay; 

if (curDay.next('day')) { 
    nextDay = curDay.next('day'); 
} else if (curDay.closest('week').find('day')) { 
    nextDay = curDay.closest('week').find('day:first-child'); 
} else if (curDay.closest('month').siblings('month').find('week day')) { 
    nextDay = curDay.closest('month').next('month') 
     .find('week:first-child day:first-child') 
} 

阿伦的回答是好,但。

+1

如果下个月在下个月 –

+0

好的电话怎么样?这变得更加复杂。 – isherwood

+0

@ A.Wolff是的,但这不是问题的一部分。 :) – epascarello

相关问题