我使用fadeIn()错了吗?

看看fadeIn()我得到的印象是我只需要将.fadeIn("slow")到这样的元素中

 $('#template').tmpl(data).prependTo('#content').fadeIn("slow"); 

但它立即出现,甚至没有出错。

这里可以看到

http://jsfiddle.net/HYLYq/8/

 $(document).ready(function(){ $('form').live('submit', function(){ var aform = $(this).serializeArray(); var data = {}; var i = aform.length; while(i--) { data[aform [i].name] = aform [i].value; } $('#template').tmpl(data).prependTo('#content').fadeIn("slow"); return false; }); }); 
                  ${title} ${owner}  

知道什么是错的吗?

在将它附加到DOM之前,您需要.hide()它。

 $('#template').tmpl(data).hide().prependTo('#content').fadeIn("slow"); 

或者,你可以把style="display:none;" 在您的模板的HTML中,然后您将不需要.hide()

编辑:此外,您的模板只是文本。 因此,.hide()将无法工作,除非您先将其包装。

应该可以正常工作。

首先隐藏元素,然后只显示fadein效果

 $(document).ready(function(){ $('form').live('submit', function(){ var aform = $(this).serializeArray(); var data = {}; var i = aform.length; while(i--) { data[aform [i].name] = aform [i].value; } $('#template').tmpl(data).prependTo('#content'); $("#content").hide(); $("#content").fadeIn("slow"); return false; }); });