微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

JQuery ul li选择列表

尝试使用JQuery使用class next和class prev例如滚动查看ul li列表.

    唯一的问题是我只希望所选的li可见.所以不知何故需要索引李的?非常感谢 – 提前感谢

    最佳答案
    这应该这样做:

    // Hide all but the first
    $('.selectoption li').not(':first').hide();
    
    // Handle the click of prev and next links
    $('.prev,.next').click(function() {
        // Determine the direction,-1 is prev,1 is next
        var dir = $(this).hasClass('prev') ? -1 : 1;
        // Get the li that is currently visible
        var current = $('.selectoption li:visible');
    
        // Get the element that should be shown next according to direction
        var new_el = dir < 0 ? current.prev('li') : current.next('li');
    
        // If we've reached the end,select first/last depending on direction
        if(new_el.size() == 0) {
            new_el = $('.selectoption li:'+(dir < 0 ? 'last' : 'first'));
        }
    
        // Hide them all..
        $('.selectoption li').hide();
        // And show the new one
        new_el.show();
    
        // Prevent the link from actually redirecting the browser somewhere
        return false;
    });
    

    原文地址:https://www.jb51.cc/jquery/428850.html

    版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

    相关推荐