我試圖檢測這是否是列表的最後一個元素。此代碼無效。什麼會?處理JQuery:最後一個選擇器
if((visel).is($('#twitnews li:last'))) {
var nextel = $('#twitnews li').first();
}
else {
var nextel = $(visel).next();
}
HTML(動態生成的,但這裏是從一個頁面的源代碼)
<div id="twitnews" style="padding-left:20px; line-height:20px; float:left;">
<li>
Rawwwwrrrr! (@ Great Life Golf & Fitness- Berkshire) http://4sq.com/kCoZKV
</li>
<li>
Swinley Forest Golf Club, Coronation Road, Ascot, Berkshire - Golf Courses http://t.co/fuoN2LW via @AddThis
</li>
<li>
Had to resort to biking indoors tonight. (@ Great Life Golf & Fitness- Berkshire) http://4sq.com/jhbqK2
</li>
<li>
In my golf course review of The Berkshire Blue course I found this to be a great day out, the course is fantastic... http://fb.me/AYkQDseI
</li>
<li>
I'm at Berkshire Hills Golf Club http://4sq.com/kUAPK2
</li>
<li>
Played Berkshire Valley GC in Morris County NJ. Course was really nice. Pics and video review of the course. http://bit.ly/mAjRcz
</li>
<li>
Review for: The Berkshire Golf Club Blue Course. Great course http://bit.ly/hUqV8e
</li>
<li>
A group of four friends from West Berkshire are getting ready to tee off for a charity golf challenge http://bit.ly/l1IWD6
</li>
<li>
I'm at Great Life Golf & Fitness- Berkshire (3720 SW 45th St., at Stone Ave., Topeka) http://4sq.com/jbOX6g
</li>
<li>
Berkshire golf club, hang your head in shame with the state those greens were in! Worst greens i have putted on EVER! #horrific
</li></div>
<script type="text/javascript">
$('#twitnews li').hide();
$('#twitnews li').first().fadeIn(300, function fade(){
var visel = $('#twitnews li:visible');
if($(visel).is($('#twitnews li:last'))) {
var nextel = $('#twitnews li').first();
}
else {
var nextel = $(visel).next();
}
$(visel).delay(3000).fadeOut(300, function(){
$(nextel).fadeIn(300, function(){fade()});
});
});
</script>
可以粘貼在這裏你的HTML? – 2011-05-14 15:11:47
現在完成問題 – 2011-05-14 15:40:17
檢查'$('#twitnews li')'在firebug中的值。看看它有多少元素返回 – 2011-05-14 15:41:46