升级到 jQuery 1.3.2 后选择器回归
我最近将一个应用程序从 jQuery 1.2 升级到 1.3.2 - 我们发现了一个相当奇怪的回归。
对于一些大约像这样的 html(稍微简化了一点),
<div id="steps">
<div class="step">
<span>step #1</span>
<div class="removeStep"> X </div>
</div>
<div class="step">
<span>step #2</span>
<div class="removeStep"> X </div>
</div>
</div>
我们之前为所有步骤附加了一个这样的事件:
$("#steps").find(".removeStep").click(removeStepFunc)
在 1.2 下,这将找到所有步骤,甚至是我们动态添加的步骤。在 1.3 下,这只能找到第一步。
这也不起作用:
#("#steps .removeStep").click(removeStepFunc)
但是,这确实有效:
#("#steps).children().find(".removeStep").click(removeStepFunc)
我显然可以解决这个问题,但这确实让我有点紧张,也许还有其他类似的回归影响我们现在升级的应用程序,这些回归只会在某些情况下出现当我们有多个元素要匹配时的情况。
我还看到另一个问题,我怀疑这可能是同一个问题?
I've recently upgraded an application from jQuery 1.2 to 1.3.2 - and we've found a rather strange regression.
For some html approximately like this (simplified a bit)
<div id="steps">
<div class="step">
<span>step #1</span>
<div class="removeStep"> X </div>
</div>
<div class="step">
<span>step #2</span>
<div class="removeStep"> X </div>
</div>
</div>
We previously attached an event like so, for all the steps:
$("#steps").find(".removeStep").click(removeStepFunc)
Under 1.2 this would find all the steps, even ones we dynamically added. Under 1.3 this only ever finds the first step.
This also doesn't work:
#("#steps .removeStep").click(removeStepFunc)
However, this does:
#("#steps).children().find(".removeStep").click(removeStepFunc)
I can obviously work around the issue, but It does make me a little nervous that perhaps there are other similar regressions affecting the application now we have upgraded, that will only present themselves in some cases when we have more then one element to match.
Also I see this other question, which I suspect might be the same issue?
jQuery selector bug? composed selector vs. simple selector & find()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试以下操作:
或
step #1
X
step #2
X
更新
这样的事情怎么样? (未经测试):
Try the following:
or
step #1
X
step #2
X
UPDATE
What about something like this? (untested):
在偶然发现这篇文章后现已解决此问题:
http://groups .google.com/group/jquery-en/browse_thread/thread/ae61896a809f6cf0
遇到的问题是由于我们使用与 jQuery 1.3 不兼容的旧版本 jQuery Validator 插件 (v1.3) 造成的.2.现在我们已将其更新到 v1.6,该问题已得到解决。
Have now resolved this issue after stumbling across this post:
http://groups.google.com/group/jquery-en/browse_thread/thread/ae61896a809f6cf0
The problems were were experiencing were caused by our use of an old version of the jQuery Validator plugin (v1.3) that was incompatible with jQuery 1.3.2. The problem has been resolved now that we've updated it to v1.6.