jQuery $(this).find()和$(selector,this)不起作用

我无法让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'); }); 

应该做同样的事情:在每个.chamber选择前20个(或19?)。 .chamber ,然后将它们变成红色。

不幸的是,实际发生的是它们都抛出相同的错误:

 Uncaught exception: ReferenceError: Undefined variable: YName Error thrown at line 19, column 8870 in (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 (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 (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 (Y, X, V, W) in jquery-1.3.2.min.js: return T(Y,X,V,W) called from line 12, column 5629 in (E) in jquery-1.3.2.min.js: o.find(E,this[0],F); called from line 169, column 3 in (): $(this).find('.cell').slice(0,19).css('background-color','red'); called via Function.prototype.call() from unknown location in (G, K, F) in jquery-1.3.2.min.js: /* no source available */ called from line 12, column 2276 in (F, E) in jquery-1.3.2.min.js: return o.each(this,F,E) called from line 168, column 2 in (): $('.chamber').each(function(){ called from line 26, column 460 in (): a.call(s,c); 

我究竟做错了什么?

首先,你是对的,两种语法都是等价的。

你的minified jQuery脚本似乎有问题。 我从googlecode下载了同一个,我在那里找不到任何YName变量。

我会在这里说道,并且说由于某种原因,对GetElementsByName()调用已经出现乱码。 尝试使用脚本的新副本。

看到这个例子:它运作良好http://jsfiddle.net/FCFmy/