是什么决定了jQuery链中方法的执行顺序? [英] What determines the execution order of methods in jQuery chains?
本文介绍了是什么决定了jQuery链中方法的执行顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
HTML代码
<div id="foo">
<h1>foo</h1>
<p>Pellentesque habitant morbi tristique.</p>
</div>
<div id="bar">
<h1>bar</h1>
</div>
jQuery代码
$('#bar').click(function () {
$('#foo p').hide('slow').appendTo('#bar').show('slow');
})
预期结果
点击#bar时
- 隐藏
p
元素#foo
- 追加
p
到#bar
- 显示
p
这是现在是的孩子#bar
- hide the
p
element in#foo
- append
p
to#bar
- show
p
which is now a child of#bar
实际结果
- 将
p
附加到#bar
- 隐藏
#foo
中的p
元素 - 显示
p
现在是的孩子#bar
- append
p
to#bar
- hide the
p
element in#foo
- show
p
which is now a child of#bar
问题
- 什么决定jQuery链中方法的执行顺序?
- 我如何确保eac h事件在下次启动之前完成?
推荐答案
如果你想等到每个动画完成在执行下一步之前,请使用文档中详细介绍的动画回调:
If you want to wait until each animation completes before doing the next step, use the animation callbacks detailed in the documentation:
$('#bar').click(function () {
$('#foo p').hide('slow', function(){
$(this).appendTo('#bar').show('slow');
});
});
这篇关于是什么决定了jQuery链中方法的执行顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文