这个回调函数如何理解?

function a(callback)   {     
    callback();   
}   
function b(){   
alert("我是回调函数b");     
}   
a(b);

上面是一个简单的回调函数的示例,我可以理解。
下面的代码中,将ligthOn,lightOff都称为回调函数,我一下想不通,请解释一下。

<html><head><title>使用JavaScript指定事件响应函数</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">function lightOn(){    document.images[0].src = "eg_bulbon.gif";
}function lightOff(){    document.images[0].src = "eg_bulboff.gif";
}window.onload = function(){    document.images[0].onmouseover = lightOn;    document.images[0].onmouseout = lightOff;
}</script></head><body><img src="eg_bulboff.gif" /></body></html>


富国沪深
浏览 541回答 1
1回答

慕的地6264312

window.onload = function(){&nbsp; &nbsp; document.images[0].addEventListener('mouseover',lightOn)&nbsp; &nbsp; document.images[0].addEventListener('mouseout',lightOff)}这样写就像了
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript