jQuery这个在这个里面
我有以下jQuery,但它不起作用,我认为答案可能是因为我在“this”中使用了“this” 如何使“this”仅适用于当前函数中发生的事情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的新手 当您处于另一个
.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方法。谢谢,这样做了。如果可以的话,我会接受的。请看。现在,我已经编辑了答案。请看。现在,我已经编辑了答案。