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;
    });
    

    相关文章

    页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
    jQuery实时显示日期、时间 html: &lt;span id=&quot...
    jQuery 添加水印 &lt;script src=&quot;../../../.....
    中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
    1. 用Response.Write方法 代码如下: Response.Write(&q...
    Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...