gpt4 book ai didi

jquery - jQuery 1.5.2 中未记录的重大更改

转载 作者:行者123 更新时间:2023-12-01 04:54:05 24 4
gpt4 key购买 nike

我正在尝试使用 jQuery 插件,CheckTree实现可选择项目的树。演示页面(上面的链接)引入了 jQuery 1.2.6 ...正如您所料,我的网站有更新的内容。

经过反复试验,该演示已停止使用 jQuery 1.5.2 或更高版本。有趣的是,release notes说 jQuery 1.5.2 只是一个错误修复版本,并没有引入任何重大更改。我已将问题归结为最简单的形式:

<!DOCTYPE html>
<html lang="en-gb">
<head>
<meta charset="utf-8">
<title>Breaking change in jQuery 1.5.2?</title>
</head>
<body>
<input type="checkbox">
<button>Click me</button>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.js"></script>
<script>
$(function(){
$(':checkbox').change(function(){ console.log('input checkbox change event'); });
$("button").click(function(){
console.log('button clicked');
$(":checkbox").click();
});
});
</script>
</body>
</html>

在 jQuery 1.5.1 中,单击按钮时不会触发复选框的更改事件。在 jQuery 1.5.2 中,更改事件触发。

换句话说,当使用 jQuery 1.5.1 时,单击按钮会产生以下控制台输出:

button clicked

使用 jQuery 1.5.2 时,单击按钮时会记录以下内容:

button clicked
input checkbox change event

是否有任何文档可以解释为什么会发生此更改,以及我可以采取哪些措施来解决此问题?该插件要求复选框更改事件不是由 $(":checkbox").click() 触发。

最佳答案

我怀疑这更多的是一个正在修复的错误,而不是破坏功能。换句话说,CheckTree 插件依赖于 jQuery bug,因此当 bug 修复后插件就崩溃了。

我刚刚与一位 jQuery 开发人员确认了这一点。他说:

I remember that one well. Some DOM methods should end up firing multiple events if you invoke them. It was a bug that older jQuery did not allow this. As far as it being a 'breaking change', well... it was 'fixing change' for a lot of people. If you depended on the bug then yeah, your code broke.

以下是来自 github 的相关拉取请求:https://github.com/jquery/jquery/pull/260

希望能回答这个问题。

关于jquery - jQuery 1.5.2 中未记录的重大更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16105360/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com