我正在尝试将单击的事件 (event.target) 传递给单击时调用的函数内的函数,我该如何执行此操作?
function showGrid(){
updateTag()
}
function updateTag(){
/*how do i get the event.target passed here? */
alert(e.target)
}
$(".gridViewIcon").click(function(e) {
showGrid();
});
最佳答案
只需通过函数调用向下传递事件参数对象即可。
function showGrid(e){
updateTag(e);
}
function updateTag(e){
/*how do i get the event.target passed here? */
alert(e.target);
}
$(".gridViewIcon").click(function(e) {
showGrid(e);
});
<小时/>
要将参数包含到嵌套 jQuery 函数中,您可以在变量上创建一个闭包,如下所示:
function updateTag(e){
alert(e.target);
...
var x = e;
something.each( function(i) { alert(x.target); } );
}
关于javascript - 将 e.target 传递给单击元素时调用的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1440334/