<html>
<head>
<title>回调函数(callback)</title>
<script language="javascript" type="text/javascript">
function test(){
var score = document.getElementById("score").value;
myfun(score,function(){
alert("这是回调函数,应该在最后");
});
}
function myfun(num,callback){
if(num<60){
alert("不及格");
}else if(num<90){
alert("良好");
}else{
alert("优秀");
}
callback();
}
</script></head>
<body>
<h1>学习js回调函数</h1>
成绩:<input type="text" >>
<input type="button" value="判断" onclick="test()" />
<p>应该能看到调用了两个回调函数</p>
</body>
</html>
以上是回调函数的一个示例,来自于:http://www.cnblogs.com/Sunnor/p/4447446.html
它的主要 作用是在当一个函数执行完成后,才来执行此函数。在ajax请求中常用于根据不同的返回结果来处理不同的任务