繁体   English   中英

传递事件和 $event 之间有区别吗?

[英]Is there a difference between passing event and $event?

如果我传递event ,以下 JavaScript 函数会起作用,但如果传递$event则会出错。 两者有什么区别,为什么$event不起作用?

function IWasClicked(event) {
    alert("clicked again with event",event);
}

这不起作用,并且$event未在HTMLAnchorElement.onclick定义

<div id="about"><a class="selected-button" href="javascript:void(0)" onclick="IWasClicked($event)">About</a></div>

这有效

<div id="about"><a class="selected-button" href="javascript:void(0)" onclick="IWasClicked(event)">About</a></div>

所以在使用$event时你会得到一个引用错误,因为没有任何东西导致它被声明。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM