JQuery ul li选择列表

前端之家收集整理的这篇文章主要介绍了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.f2er.com/jquery/428850.html

    猜你在找的jQuery相关文章