在 JavaScript 中,如果不作为 arg 传递,如何确定当前事件?
在任意 JavaScript 函数中,我希望确定上游事件。
事件监听函数没有将事件传递给当前函数。据我所知,window.event
不是 WC3 并且不可用。
function listener(e) { subfunc(e.target); } function subfunc( element) { // here I wish to know which if any event responsible for me being called var event = ?; switch( event.type ) { ... } }
函数subfunc()
如何确定当前事件?
(如果之前问过问题,请道歉 - 似乎一定是这样 - 但无法追踪到它。)
In an arbitrary JavaScript function, I wish to determine the upstream event.
The event listener function did not pass the event do the current function. As far as I know, window.event
is not WC3 and not available.
function listener(e) { subfunc(e.target); } function subfunc( element) { // here I wish to know which if any event responsible for me being called var event = ?; switch( event.type ) { ... } }
How does function subfunc()
determine the current event?
(Apologize if question asked before - seems it must have been - but cannot track it down.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以这样做:
还有其他方式:
You can do:
Also other way:
那是不可能的。只有一个属性可以通过另一种可靠的方式访问:
event.target
=this
(前提是从事件侦听器的范围内调用该函数)。事件对象应该传递给
subfunc
。That's not possible. There's only one property which can be accessed through another, reliable way:
event.target
=this
(Provided that the function is called from within the scope of the event listener).The event object should be passed to
subfunc
.