将e.target传递给单击元素时调用的函数

ada*_*ign 0 javascript jquery

我试图将点击的事件(event.target)传递给单击时被调用的函数内的函数我将如何执行此操作?

function showGrid(){
    updateTag()
  }

function updateTag(){
    /*how do i get the event.target passed here? */
    alert(e.target) 
  }


$(".gridViewIcon").click(function(e) {
   showGrid();
  });
Run Code Online (Sandbox Code Playgroud)

wom*_*omp 5

只需通过函数调用传递event参数对象.

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);
  });
Run Code Online (Sandbox Code Playgroud)

要将参数包含在嵌套的jQuery函数中,可以像这样在变量上创建一个闭包:

 function updateTag(e){

        alert(e.target); 

        ...
        var x = e;
        something.each( function(i) {  alert(x.target); } );

      }
Run Code Online (Sandbox Code Playgroud)