jQuery和多个li AppendTo

时间:2012-01-24 01:59:14

标签: jquery list appendto

在将一些li元素添加到列表后,我遇到了一些问题。

var html包含列表项。

$(html).hide().appendTo('#thelist').fadeIn();

当加载了单个li元素时,淡入效果会起作用,但是如果有多个li的jQuery没有插入任何东西,更不用说淡入它了。

有人可以建议修复吗?

编辑1:

示例 - 该列表是我的ul而且没有隐藏。

<ul id="thelist">
   <li>entry1</li>
   <li>entry2</li>
   <li>entry3</li>
</ul>

编辑2:该列表如上所述存在于HTML中,然后jQuery添加了我想要淡化的其他li。

编辑3: html包含一个jQuery ajax调用,其中包含html,显示大约5个文章内容。 当我不使用淡入淡出或动画时,它会正确添加到ul。当我添加淡入淡出时,它会将元素添加到ul中,但它不会淡化它们。

编辑4:以下是加载功能:

 $(function() {
     $('.more').live('click',function() {
     var element = $(this);
     var msg = element.attr('id');
     $('#morebutton').html('<p><em>Loading Articles.</em></p>');
     $.ajax({
         type: 'POST',
         url: 'more.asp',
         data: 'lastmsg=' + msg,
         cache: false,
         success: function(html){
             $('#morebutton').remove();
             $(html).hide().appendTo('#thelist').fadeIn();
         }
     });
     });
 });

SOLUTION:

我通过改变来淡出:

 $(html).hide().appendTo('#thelist').fadeIn();

 var item = $(html).fadeIn();
 $('#thelist').append(item);

似乎与jQuery以特定顺序链接的方式有关。

3 个答案:

答案 0 :(得分:0)

尝试使用

之后
$(html).hide().after('#thelist').fadeIn();

答案 1 :(得分:0)

这对我来说很好。确保您的列表项和列表存在。检查任何ID的拼写错误。

http://jsfiddle.net/gftdz/1/

答案 2 :(得分:0)

不确定,但可能你想要这样的东西

$('#thelist').fadeOut('fast',function(){$('#thelist').append(html).fadeIn()});