jQuery Callback 函数

来源:互联网 发布:python正则表达式符号 编辑:程序博客网 时间:2024/05/19 19:40

Query Callback 函数

当动画 100% 完成后,即调用 Callback 函数。

典型的语法:

$(selector).hide(speed,callback)

callback 参数是一个在 hide 操作完成后被执行的函数。

错误(没有 callback)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script src="jquery.js"></script><script>$(document).ready(function(){$("button").click(function(){$("p").hide(1000);alert("现在隐藏段落!")})})</script></head><body><button type="button">Hide</button><p>内容内容</p></body></html>

效果图:



正确(有 callback)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script src="jquery.js"></script><script>$(document).ready(function(){$("button").click(function(){$("p").hide(function(){alert("现在隐藏段落!")})})})</script></head><body><button type="button">Hide</button><p>内容内容</p></body></html>
效果图:



结论:如果您希望在一个涉及动画的函数之后来执行语句,请使用 callback 函数。


0 0
原创粉丝点击