升级到 jQuery 1.3.2 后选择器回归

发布于 2024-08-13 10:21:53 字数 1051 浏览 5 评论 0原文

我最近将一个应用程序从 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)

我显然可以解决这个问题,但这确实让我有点紧张,也许还有其他类似的回归影响我们现在升级的应用程序,这些回归只会在某些情况下出现当我们有多个元素要匹配时的情况。

我还看到另一个问题,我怀疑这可能是同一个问题?

jQuery 选择器错误?组合选择器与简单选择器的比较查找()

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

各空 2024-08-20 10:21:53

尝试以下操作:

jQuery('#steps > .removeStep').click(removeStepFunc)

jQuery('#steps .step .removeStep').click(removeStepFunc)

step #1
X

step #2
X

更新

这样的事情怎么样? (未经测试):

jQuery('#steps .removeStep').click( function() {
  jQuery(this).remove(jQuery(this).parent());
});

Try the following:

jQuery('#steps > .removeStep').click(removeStepFunc)

or

jQuery('#steps .step .removeStep').click(removeStepFunc)

step #1
X

step #2
X

UPDATE

What about something like this? (untested):

jQuery('#steps .removeStep').click( function() {
  jQuery(this).remove(jQuery(this).parent());
});
纸伞微斜 2024-08-20 10:21:53

在偶然发现这篇文章后现已解决此问题:

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文