Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.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 如何引用插件的$(this)而不是每个函数的$(this)?jQuery_Javascript_Jquery - Fatal编程技术网

Javascript 如何引用插件的$(this)而不是每个函数的$(this)?jQuery

Javascript 如何引用插件的$(this)而不是每个函数的$(this)?jQuery,javascript,jquery,Javascript,Jquery,在开发一个小插件时,我发现了一个让我心碎的问题。要调用我的插件,我使用: $('#input').myPlugin(); 在某一时刻,我需要在我的插件内部使用一个插件,以下是代码: var list = [] var str = 'just a test <b>foo</b> blablabla <b>bar</b>' str.children('b').each(function(i){ // Here I want use the

在开发一个小插件时,我发现了一个让我心碎的问题。要调用我的插件,我使用:

$('#input').myPlugin();
在某一时刻,我需要在我的插件内部使用一个插件,以下是代码:

var list = []
var str = 'just a test <b>foo</b> blablabla <b>bar</b>'
str.children('b').each(function(i){  
    // Here I want use the $(this) of each function
    list.append($(this).text())
})

我如何告诉jQuery这是什么?

之前声明一个变量
var$this=$(this)
。每个
循环,并在内部回调中引用
$this

我不知道这是否是最好的方法,但这是有效的,您的答案是唯一的,所以谢谢!这是最常见的方式。很好。
hashtag.each(function(i)){ 

      // In the first "this" I want refer to $('input'), in the second, to this of each function.
      $(this).functionToFindText($(this))
}