jQuery $(this).find()和$(selector,this)不起作用
jQuery $(this).find() and $(selector,this) not working
我有麻烦让jQuery的$(this)
函数工作如预期…或者更确切地说,工作。在我看来,
$('.chamber').each(function(){
$(this).find('.cell').slice(0,19).css('background-color','red');
});
和
$('.chamber').each(function(){
$('.cell',this).slice(0,19).css('background-color','red');
});
应该做同样的事情:选择前20(或19?)每个.chamber
中的.cell
s,并使它们变为红色。
不幸的是,实际发生的是它们都抛出相同的错误:
Uncaught exception: ReferenceError: Undefined variable: YName
Error thrown at line 19, column 8870 in <anonymous function: CLASS>(W, U, V, T, Z, aa) in jquery-1.3.2.min.js:
if(Z^(YName&&(" "+YName+" ").indexOf(W)>=0))
called from line 19, column 3944 in <anonymous function: F.filter>(ad, ac, ag, W) in jquery-1.3.2.min.js:
Y=I.preFilter[ab](Y,aa,ag,ai,W,Z);
called from line 19, column 896 in <anonymous function>(Y, U, ab, ac) in jquery-1.3.2.min.js:
af=F.filter(ae.expr,ae.set);
called from line 19, column 21013 in <anonymous function: F>(Y, X, V, W) in jquery-1.3.2.min.js:
return T(Y,X,V,W)
called from line 12, column 5629 in <anonymous function: find>(E) in jquery-1.3.2.min.js:
o.find(E,this[0],F);
called from line 169, column 3 in <anonymous function>():
$(this).find('.cell').slice(0,19).css('background-color','red');
called via Function.prototype.call() from unknown location in <anonymous function: each>(G, K, F) in jquery-1.3.2.min.js:
/* no source available */
called from line 12, column 2276 in <anonymous function: each>(F, E) in jquery-1.3.2.min.js:
return o.each(this,F,E)
called from line 168, column 2 in <anonymous function>():
$('.chamber').each(function(){
called from line 26, column 460 in <anonymous function: ready>():
a.call(s,c);
我做错了什么?
首先,你是对的,两种语法是等价的。
你的迷你jQuery脚本似乎有问题。我从googlecode下载了相同的一个,我在那里找不到任何YName
变量。
我在这里冒昧地说,由于某种原因,对GetElementsByName()
的呼叫被打乱了。尝试使用脚本的新副本。
看这个例子:它工作得很好http://jsfiddle.net/FCFmy/
相关文章:
- 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 时不起作用
- jQuery $(this).find()和$(selector,this)不起作用
- Jquery使用$(this)不起作用