Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从另一个函数绑定Dom$(this)_Javascript_Jquery - Fatal编程技术网

Javascript 如何从另一个函数绑定Dom$(this)

Javascript 如何从另一个函数绑定Dom$(this),javascript,jquery,Javascript,Jquery,请看一下这段代码,让我看看如何在dom事件内部的外部函数中绑定$(this) $(“.adder”)。在(“单击”,函数()上){ updateText(); }); 函数updateText(){ $(this.next(“.mapper”).html(“明白了!”); } 左边 中间的 赖特 左边 中间的 赖特 您应该能够将其作为参数传递: $(".adder").on("click", function(){ var node = $(this); updateText

请看一下这段代码,让我看看如何在dom事件内部的外部函数中绑定
$(this)

$(“.adder”)。在(“单击”,函数()上){
updateText();
});
函数updateText(){
$(this.next(“.mapper”).html(“明白了!”);
}

左边
中间的
赖特
左边
中间的
赖特

您应该能够将其作为参数传递:

$(".adder").on("click", function(){
    var node = $(this);
    updateText(node);
});

function updateText(node){
   node.next(".mapper").html("Got You!");
}

您应该能够将其作为参数传递:

$(".adder").on("click", function(){
    var node = $(this);
    updateText(node);
});

function updateText(node){
   node.next(".mapper").html("Got You!");
}

一种方法是:

function updateText(){
   $(this).next(".mapper").html("Got You!");
}

$(".adder").on("click", updateText);
另一个是

function updateText(){
   $(this).next(".mapper").html("Got You!");
}

$(".adder").on("click", function(){
    updateText.bind(this)();
});

一种方法是:

function updateText(){
   $(this).next(".mapper").html("Got You!");
}

$(".adder").on("click", updateText);
另一个是

function updateText(){
   $(this).next(".mapper").html("Got You!");
}

$(".adder").on("click", function(){
    updateText.bind(this)();
});