0
有时您会发现我们需要javascript中的event
对象。
下面是一些代码,我们如何通过event
。在javascript函数中传递事件对象
function test(e){
console.log(e);
e.preventDefault();
console.log("you are not going to redirect");
}
HTML
<a href="www.google.com" onclick="test(event)">GOOGLE</a>
,如果你想在函数传递事件只是通过event
在函数参数。
[在事件处理函数中获取事件对象而无需将事件对象作为参数传递? (与jQuery)](http://stackoverflow.com/questions/5849370/get-the-event-object-in-an-event-handling-function-without-pass-the-event-object) –
我想使用'e.preventDefault()'你可以看到更新问题 –
你的代码semms是正确的,问题是你的代码没有显示一个代码与你的函数 – youssouf