是否可以从被调用的 JavaScript 函数中获取 JavaScript 触发事件 不传递任何事件参数?
这是示例代码:
<html>
<head>
<script>
function myFunction()
{
// How I will get from here the fired event ??
}
</script>
</head>
<body>
<p id="paragraghhh" onclick="myFunction()">
Click on this paragraph. An alert box will
show which element triggered the event.
</p>
</body>
</html>
最佳答案
在 JavaScript 函数中,您可以引用 this.event 属性。
例如,
function myFunction(){
alert(this.event.type);
}
提醒 JS 事件,在本例中为“点击”
关于javascript - 如何在不传递事件参数的情况下从 JS 函数获取触发事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15810917/