如何在 .selected 之后获得下一个天?
$('day.selected').next('day')
仅在同一周内工作几天。
<calendar>
<month>
<week>
<day/>
<day class='selected'/>
</week>
<week>
<day/> //How to get this?
<day/>
</week>
</month>
<month>
.
.
</calendar>
答案 0 :(得分:6)
作为查找第二天元素的一般解决方案(与父元素无关)
var idx = $('day.selected').index('day'),
$next = $('day').eq(idx + 1);
答案 1 :(得分:2)
试试这个:
$('.selected').parent().next().find(':first-child')
答案 2 :(得分: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')
}
但是,阿伦的答案更好。