看看fadeIn()我得到的印象是我只需要.fadeIn("slow")像这样添加一个元素
$('#template').tmpl(data).prependTo('#content').fadeIn("slow");
Run Code Online (Sandbox Code Playgroud)
但它瞬间出现,甚至没有出错.
这里可以看到
$(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;
});
});Run Code Online (Sandbox Code Playgroud)
<script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<script src="http://jqueryui.com/ui/jquery.ui.core.js"></script>
<script src="http://jqueryui.com/ui/jquery.ui.widget.js"></script>
<script src="http://jqueryui.com/ui/jquery.ui.datepicker.js"></script>
<!-- jQuery.tmpl() -->
<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"></script>
<script src="http://jqueryui.com/external/jquery.bgiframe-2.1.2.js"></script>
<script src="http://jqueryui.com/ui/jquery.ui.core.js"></script>
<script src="http://jqueryui.com/ui/jquery.ui.widget.js"></script>
<script src="http://jqueryui.com/ui/jquery.ui.mouse.js"></script>
<script src="http://jqueryui.com/ui/jquery.ui.button.js"></script>
<script src="http://jqueryui.com/ui/jquery.ui.draggable.js"></script>
<script src="http://jqueryui.com/ui/jquery.ui.position.js"></script>
<script src="http://jqueryui.com/ui/jquery.ui.dialog.js"></script>
<!-- template that will be used for inserting a form live when the okay bottom have been pressed and succeeded -->
<script type="text/x-jquery-tmpl" id="template">
${title} ${owner}
</script>
<form id="create_form" name="create_form" action="" method="post">
<input type="text" name="title" id="title" value="test1" />
<input type="text" name="owner" id="owner" value="test2" /><br class="new"/>
<button class="n" type="submit">Create</button>
</form>
<div id="content"> </div>Run Code Online (Sandbox Code Playgroud)
知道什么是错的吗?
.hide()在将它附加到DOM之前,您需要它.
$('#template').tmpl(data).hide().prependTo('#content').fadeIn("slow");
Run Code Online (Sandbox Code Playgroud)
或者,您可以放入style="display:none;"模板的HTML,然后您就不需要了.hide().
编辑:此外,您的模板只是文本.因此,.hide()将无法工作,除非您先将其包装.A <span>或<div>应该工作得很好.
| 归档时间: |
|
| 查看次数: |
119 次 |
| 最近记录: |