[英]pass the e.target to a function thats called when element is clicked
I am trying to pass the clicked event (event.target) to a function inside a function that is being called when clicked how would i do this? 我正在尝试将clicked事件(event.target)传递给在单击时被调用的函数内的函数,我该怎么做?
function showGrid(){
updateTag()
}
function updateTag(){
/*how do i get the event.target passed here? */
alert(e.target)
}
$(".gridViewIcon").click(function(e) {
showGrid();
});
Just pass the event argument object down through your function calls. 只需将事件参数对象向下传递给函数调用即可。
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);
});
To include the argument into a nested jQuery function, you can create a closure on the variable like so: 要将参数包含在嵌套的jQuery函数中,您可以像下面这样在变量上创建一个闭包:
function updateTag(e){
alert(e.target);
...
var x = e;
something.each( function(i) { alert(x.target); } );
}
Add e
as a parameter for each function you need to pass it too. 为每个需要传递它的函数添加e
作为参数。
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);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.