Jquery使用$(this)不起作用
jquery using $(this) not working
大家好,下面是我的代码。
$('.first').click(function(){
$('.second').each(function(){
console($(this));
});
});
我想引用console($(this));
到$('.first')
,而不是$('.second')
..我认为我们可以通过引用变量来做到这一点,但仍然没有修复:(
$('.first').click(function(){
var self = this;
$('.second').each(function(){
console($(self));
});
});
或 jQuery.proxy () 方法:
$('.first').click(function(){
$('.second').each($.proxy(function(){
console($(this));
}, this));
});
$('.first').click(function(){
$('.second').each(function(){
console($(this));
}.bind(this));
});
由于this
依赖于上下文,您可以通过明确地说明您期望this
是什么来使这一点更清楚:
$('.first').click(function(){
var first = this;
$('.second').each(function(){
console($(first));
});
});
相关文章:
- jQuery(this).Pparent().Pparente().Prent().find()在iPad上不起作用
- Javascript:this.value 函数不起作用
- Javascript onchange(this.value,this.value)在ipad上不起作用
- $(this).attr({class:“activeTab”});不起作用,因为这是未定义的
- Firebase child_added“this”不起作用
- $(this) 在 onclick 属性中不起作用
- 不确定为什么使用$(this)的函数没有'不起作用
- JS this和self-don'不起作用
- jQuery this.href 字符串比较不起作用
- $(this).html 在 jquery 中不起作用
- jQuery $this 在网页上不起作用
- 滑动面板 .stop() 在 $(this).next 上不起作用
- jquery $(this).find 对我不起作用
- jQuery this.data-x 不起作用
- React-native:this.navigator.pop 不起作用
- Jquery - this.form不起作用
- $(this) 在 .append() 中不起作用
- jQuery 切换在 this.name 时不起作用
- $(“.class”).width($(this)..) 不起作用
- $this->_request->isXmlHttpRequest() 不起作用