当事件处理程序函数像这样注册时:
element.onload = function()
{
var something = Selector("identifier", "inline", 1).FadeIn("inline", 1);
CenterElement(something);
};
一旦从另一个处理程序函数内部开始执行,是否有方法停止执行?让这个处理程序函数看起来像这样:
another.onclick = function()
{
//Cancel the execution of the above function here
document.getElementById("start").innerHTML = "Start Slideshow";
this.FadeOut();
};
Selector
返回一个与问题本身无关的特殊包装器对象,因此省略了实现。
众所周知,通过将undefined
分配给处理程序变量可以阻止处理程序函数的执行,但如果它已经开始执行,如何停止它呢?
这里缺少一个重要的概念。
在javascript中,只有一个执行线程。虽然您可能认为onclick
在执行onload
时被调用,但这完全是错误的。
我不知道您使用的是什么框架,但在jQuery中,您可以执行以下操作:
another.onclick = function()
{
//Cancel the execution of the above function here
Selector("identifier", "inline", 1).stop();
// ...other stuff
};