[英]pass the e.target to a function thats called when element is clicked
我正在嘗試將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();
});
只需將事件參數對象向下傳遞給函數調用即可。
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); } );
}
為每個需要傳遞它的函數添加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.