处理 JQuery :last 选择器

发布于 2024-11-06 21:08:12 字数 2379 浏览 4 评论 0原文

我试图检测这是否是列表的最后一个元素。这段代码不起作用。什么会?

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>

I am trying to detect whether this is the last element of a list. This code did not work. What would?

if((visel).is($('#twitnews li:last'))) {
        var nextel =  $('#twitnews li').first();
    }
    else {
    var nextel = $(visel).next();
    }

HTML: (dynamically generated but here is the source from one page)

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

霓裳挽歌倾城醉 2024-11-13 21:08:12

如果您使用 jquery 1.6,则效果如下:

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

如果您低于 1.6,那么您需要更改此设置:

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

将 jquery 对象传递给 is 的功能是在 1.6 中添加的。您需要执行以下操作:

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

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

This works as is if you're using jquery 1.6:

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

if you're below 1.6 then you need to change this:

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

The ability to pass a jquery object to is was added in 1.6. You would need to do something like this:

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

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

甚是思念 2024-11-13 21:08:12

您缺少 $

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

You're missing the $

if($(visel).is($('#twitnews li:last')))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文