简体   繁体   English

在jQuery中从底部到顶部获取ul和li的ID

[英]Get id of ul and li from bottom to top in jquery

now i am using jquery to get ids of ul and li from top to bottom .but i cant able to get it from bottom to top . 现在我正在使用jquery从上到下获取ul和li的ID。但是我无法从下到上获取它。 iam using the following code 我使用以下代码

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

 <script type="text/javascript">

        function next_click()
        {
        alert("next");
        var toHighlight = jQuery('.current').next().length > 0 ? jQuery('.current').next() : jQuery('#men_shirt li').first();
        jQuery('.current').removeClass('current');
        toHighlight.addClass('current');
        $('#men_shirt ul li').each(function(i)
        {
           var iid=$(this).attr('id'); 
           alert("sdfsdf"+iid);
        });

        var a=jQuery('li').hasClass('current');
        alert(a);

        if(a=='style')
        {
        set_menuselected('Style');
        }
        } 

</script>

Please advise on this 请对此提供意见

Use .get().reverse() See Help 使用.get().reverse()参见帮助

$.each('#men_shirt ul li').get().reverse(),function(i)//use get.reverse method()
{
   var iid=$(this).attr('id'); 
   alert("sdfsdf"+iid);
});

You can extend jQuery with the reverse method: 您可以使用反向方法扩展jQuery:

jQuery.fn.reverse = [].reverse;

And then: 接着:

$('#men_shirt ul li').reverse().each(function() {
    ...
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM