Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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
jQuery这个在这个里面_Jquery - Fatal编程技术网

jQuery这个在这个里面

jQuery这个在这个里面,jquery,Jquery,我有以下jQuery,但它不起作用,我认为答案可能是因为我在“this”中使用了“this” 如何使“this”仅适用于当前函数中发生的事情 抱歉,如果这不够详细,我是jQuery的新手 当您处于另一个.each()的上下文中时,“this”的含义会发生变化。如果需要引用“外部this”,请在变量中捕获它: $('.field-name-field-choose-a-service input:checked').each(function() { var outerThis = thi

我有以下jQuery,但它不起作用,我认为答案可能是因为我在“this”中使用了“this”

如何使“this”仅适用于当前函数中发生的事情


抱歉,如果这不够详细,我是jQuery的新手

当您处于另一个
.each()
的上下文中时,“this”的含义会发生变化。如果需要引用“外部this”,请在变量中捕获它:

$('.field-name-field-choose-a-service input:checked').each(function() {
    var outerThis = this;
    var unitname = $(this).closest('.form-item').text();
    $('.field-name-field-choose-a-package .form-type-checkbox').each(function() {
        // "this" refers to the "inner this"
        // "outerThis" refers to the "outer this"
    });
});

}))

当您处于另一个
.each()
的上下文中时,“this”的含义会发生变化。如果需要引用“外部this”,请在变量中捕获它:

$('.field-name-field-choose-a-service input:checked').each(function() {
    var outerThis = this;
    var unitname = $(this).closest('.form-item').text();
    $('.field-name-field-choose-a-package .form-type-checkbox').each(function() {
        // "this" refers to the "inner this"
        // "outerThis" refers to the "outer this"
    });
});

}))

尝试将
$(this)
元素存储在变量中,然后使用变量而不是
$(this)
尝试将
$(this)
元素存储在变量中,然后使用变量而不是
$(this)

什么东西不起作用?您可以将
元素缓存到内部
每个
元素之外。添加
var$checkedService=$(此项)在外部
每个
的开头,并在内部
每个
中使用此代码。到底什么不起作用?您可以在内部
每个
外部缓存
。添加
var$checkedService=$(此项)
在外部
每个
的开头,在内部
每个
中使用这个。我想OP想要缓存
$(这个)
,这样就可以直接对它调用jQuery方法。谢谢,这样做了。如果可以的话,我会接受的。我想OP希望缓存
$(this)
,这样就可以直接对其调用jQuery方法。谢谢,这样做了。如果可以的话,我会接受的。请看。现在,我已经编辑了答案。请看。现在,我已经编辑了答案。