怎么把ul下边的某个li放到第一个位置

$('#user-order-list').find('li').each(function () {

        

            if($(this).data('id')==shushe_id){
            
            
                if($(this).find('img').length<=1){

                    $(this).find('a').append("<img src='../img/books_list.jpg' class='books_list_icon'>");
                    $(this).eq(0);
                }

            }else {
            }
        });

在插如图片后,下一步移动位置不知道该怎么操作了

阅读 8.4k
2 个回答

这是你要的功能?

$('#user-order-list').find('li').each(function () {
    if($(this).data('id')==shushe_id){
        if($(this).find('img').length<=1){
            $(this).find('a').append("<img src='../img/books_list.jpg' class='books_list_icon'>");
        }
        $('#user-order-list').prepend($(this));
    }else {
    }
});

jquery有个insertBefore()可以满足你的要求
例如:

$(selector).insertBefore($("li").eq(0))
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题