在事件处理程序中触发javascript默认动作
问题描述:
我想知道如何在发生其他事情之前触发默认动作。特别是,我正在使用第三方库,如果我使用事件处理程序并调用其中一个函数,它们将覆盖默认操作。因此,作为解决方法,我希望默认操作在其库函数被调用之前发生。在事件处理程序中触发javascript默认动作
有没有办法做到这一点?
非常感谢!
答
我假设你的意思是你想在事件被浏览器处理后调用它们的函数。
为此,请在延迟后使用setTimeout
方法执行。
例如,
//In the event handler:
setTimeout(function() {
//This code will execute 5 milliseconds later, and only after your code finishes.
//Call their function here
}, 5); //That means a 5 millisecond delay.
//You can increase it if you want to.