2011-05-14 4 views
1

이것이 목록의 마지막 요소인지 여부를 감지하려고합니다. 이 코드는 작동하지 않았습니다. 어떤 것?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> 
+0

당신이 당신의 HTML 여기에 붙여 넣을 수 있습니다 : 당신이 뭔가를 할 필요가? –

+0

이제 질문을 완료 –

+0

'$ ('twitnews li ')'값을 파이어 버그에서 확인하십시오. 반환하는 요소 수를 확인하십시오 –

답변

2

을 놓치고있다 (동적 여기서 생성하지만 한 페이지에서 소스입니다) jquery 1.6 :

http://jsfiddle.net/Da8ja/2/

이 1.6 이하라면 당신은이 설정을 변경해야합니다

visel.is($('#twitnews li:last')) 

1.6에 추가 된 is에 JQuery와 개체를 전달할 수있는 능력.

if(visel[0]==$('#twitnews li:last')[0]) { 

http://jsfiddle.net/Da8ja/3/

-1

이 같이 작동 $

if($(visel).is($('#twitnews li:last'))) 
+0

예 그래도 그걸 보았지만 여전히 작동하지 않습니다 –

+0

은 .htx 파일을 붙여 넣습니다. –

+0

이제 질문이 –