jQuery 3.5.0 是 jQuery 的一个版本更新,它带来了一些新特性和改进

jQuery团队发布了3.5.0版本,主要修复了安全漏洞,并为即将发布的4.0版本做准备,引入了.even()和.odd()方法替代位置选择器,同时对Ajax脚本传输进行了改进。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

jQuery 3.5.0 是 jQuery 的一个版本更新,它带来了一些新特性和改进。以下是关于这个版本的一些主要信息:

  1. 性能优化:jQuery 3.5.0 对内部代码进行了优化,提高了执行效率,特别是在处理大型文档时的性能表现更好。

  2. 更好的错误处理:新版本增强了错误处理机制,使得在开发过程中更容易识别和调试问题。

  3. 弃用旧功能:为了保持库的轻量级和高效性,jQuery 3.5.0 弃用了某些不再推荐使用的功能,鼓励开发者采用更现代的解决方案。

  4. 兼容性:jQuery 3.5.0 继续支持旧版浏览器,确保了广泛的兼容性。

  5. 新功能:虽然 3.5.0 主要是维护和优化,但仍然引入了一些小的新功能和改进,以提升开发者的体验。

  6. 文档和示例:官方文档和示例也得到了更新,帮助开发者更好地理解和使用 jQuery 3.5.0。

jQuery 3.5.0 引入了多项性能优化措施,旨在提高脚本的执行效率和减少内存使用。以下是一些具体的性能优化措施:

  1. 事件委托优化:通过改进事件委托的处理方式,减少了对DOM操作的次数,从而提高了事件处理的性能。
  2. Ajax请求优化:增强了Ajax请求的错误处理机制,并优化了网络请求的管理,以减少不必要的网络流量和提高响应速度。
  3. 动画性能提升:改进了动画队列的管理,使得动画更加流畅,同时减少了可能的性能瓶颈。
  4. 内存管理优化:通过更智能的内存管理策略,减少了内存泄漏的风险,特别是在处理大量数据或频繁的DOM操作时。
  5. 选择器引擎优化:优化了Sizzle选择器引擎,提高了元素选择的速度和准确性。
  6. 代码压缩和混淆:通过进一步压缩和混淆jQuery的源代码,减小了文件大小,从而加快了页面加载速度。

这些优化措施共同作用,使得jQuery 3.5.0在处理复杂交互和大量数据时更加高效和稳定。

jQuery 3.5.0中的事件委托是一种非常有效的方法,可以显著提高页面性能。事件委托利用了事件冒泡的原理,将事件处理程序绑定到父元素上,而不是每个子元素上。这样可以减少内存消耗和提升响应速度,特别是在动态内容或大量元素的情况下。

以下是如何使用jQuery 3.5.0实现事件委托的步骤:

  1. 选择父元素:首先,你需要选择一个合适的父元素,这个父元素应该包含所有需要绑定事件的子元素。

  2. 使用.on()方法绑定事件:在jQuery中,你可以使用.on()方法来绑定事件。这个方法允许你指定一个选择器,该选择器匹配的元素触发事件时,事件处理函数将被执行。

    例如,如果你有一个列表,列表项可能会动态添加,你可以这样做:

    $('#parent').on('click', 'li', function() {
        // 这里的代码将在点击任何<li>元素时执行
        alert($(this).text()); // 显示被点击的<li>元素的文本
    });
    

    在这个例子中,无论何时添加新的<li>元素到#parent元素中,点击这些新元素都会触发事件处理函数。

  3. 优化选择器:在使用事件委托时,确保你的选择器尽可能具体,这样可以避免不必要的事件处理调用。过于宽泛的选择器可能会导致性能问题。

  4. 避免过度使用:虽然事件委托可以提高性能,但过度使用或不当使用也可能导致代码难以维护和理解。确保只在确实需要处理大量相似元素事件时使用事件委托。

通过以上步骤,你可以有效地利用jQuery 3.5.0中的事件委托来提高页面的性能,尤其是在处理大量动态内容时。
Posted on April 10, 2020 by Timmy Willison
jQuery 3.5.0 has been released! As usual, the release is available on our cdn and the npm package manager. Other third party CDNs will probably have it soon as well, but remember that we don’t control their release schedules and they will need some time.

We hope you’re staying healthy and safe while so many of us are stuck at home. With a virus ravaging the planet, we realize that jQuery may not be a high priority for you or the sites you manage. When you do have a moment, we recommend that you review this new version and upgrade.

Security Fix
The main change in this release is a security fix, and it’s possible you will need to change your own code to adapt. Here’s why: jQuery used a regex in its jQuery.htmlPrefilter method to ensure that all closing tags were XHTML-compliant when passed to methods. For example, this prefilter ensured that a call like jQuery(“

”) is actually converted to jQuery(“
”). Recently, an issue was reported that demonstrated the regex could introduce a cross-site scripting (XSS) vulnerability.

The HTML parser in jQuery <=3.4.1 usually did the right thing, but there were edge cases where parsing would have unintended consequences. The jQuery team agreed it was necessary to fix this in a minor release, even though some code relies on the previous behavior and may break. The jQuery.htmlPrefilter function does not use a regex in 3.5.0 and passes the string through unchanged.

If you absolutely need the old behavior, using the latest version of the jQuery migrate plugin provides a function to restore the old jQuery.htmlPrefilter. After including the plugin you can call jQuery.UNSAFE_restoreLegacyHtmlPrefilter() and jQuery will again ensure XHTML-compliant closing tags.

However, to sanitize user input properly, we also recommend using dompurify with the SAFE_FOR_JQUERY option to sanitize HTML from a user. If you don’t need the old behavior, but would still like to sanitize HTML from a user, dompurify should be used without the SAFE_FOR_JQUERY option, starting in jQuery 3.5.0. For more details, please see the 3.5 Upgrade Guide.

Features
With what we call “positional selectors” being deprecated and slated for removal in jQuery 4.0, we’ve added the last two necessary replacement methods. Specifically, we’ve added the .even() and .odd() methods to replace the :even and :odd selectors. With these methods in place, we can safely remove these overly complicated selectors in jQuery 4.0.

Another small feature that we’ve added to this release is the ability to add a context to jQuery.globalEval. This was done as part of fixing a bug with script execution in iframes.

Fixes
One bug worth highlighting is a bug we fixed in the Ajax script transport. jQuery used to evaluate any response to a request for a script as a script, which is not always the desired behavior. This is different than other data types where such a convention was fine (e.g. in the case of JSON). jQuery 3.5.0 will now only evaluate successful HTTP responses.

Other bug fixes and improvements include performance improvements in Sizzle, support for massive arrays in jQuery.map, using the native .flat() method where supported, a fix for syntax errors in the AMD modules, several improvements to our testing infrastructure, and more. You’ll find the full changelog below.

Deprecations
It wouldn’t be a jQuery release without some deprecations. In jQuery 3.5.0, we’ve put jQuery.trim on the list. JavaScript’s own String.prototype.trim() is an easy replacement for it.

We’ve also put AJAX event aliases on the list, they can be replaced by .on(“ajaxStart”, …) and the like. jQuery Migrate will warn about these now-deprecated methods, but they’ll stick around until jQuery 4.0.

Upgrading
Aside from the change to no longer ensure XHTML-compliant tags for you, we do not expect other compatibility issues when upgrading from a jQuery 3.0+ version. To upgrade, have a look at the new 3.5 Upgrade Guide. If you haven’t yet upgraded to jQuery 3+, first have a look at the 3.0 Upgrade Guide.

The jQuery Migrate plugin will help you to identify compatibility issues in your code. Please try out this new release and let us know about any issues you experienced.

Download
You can get the files from the jQuery CDN, or link to them directly:

https://code.jquery.com/jquery-3.5.0.js

https://code.jquery.com/jquery-3.5.0.min.js

You can also get this release from npm:

npm install jquery@3.5.0

Slim build
Sometimes you don’t need ajax, or you prefer to use one of the many standalone libraries that focus on ajax requests. And often it is simpler to use a combination of CSS and class manipulation for web animations. Along with the regular version of jQuery that includes the ajax and effects modules, we’ve released a “slim” version that excludes these modules. The size of jQuery is very rarely a load performance concern these days, but the slim build is about 6k gzipped bytes smaller than the regular version. These files are also available in the npm package and on the CDN:

https://code.jquery.com/jquery-3.5.0.slim.js

https://code.jquery.com/jquery-3.5.0.slim.min.js

These updates are already available as the current versions on npm and Bower. Information on all the ways to get jQuery is available at https://jquery.com/download/. Public CDNs receive their copies today, please give them a few days to post the files. If you’re anxious to get a quick start, use the files on our CDN until they have a chance to update.

Thanks
Thank you to all of you who participated in this release by submitting patches, reporting bugs, or testing, including Ahmed S. El-Afifi, Michał Gołębiowski-Owczarek, Wonseop Kim, Dave Methvin, Shashanka Nataraj, Pat O’Callaghan, Sean Robinson, Christian Oliff, Christian Wenz, and the whole jQuery team.

We also would like to thank Masato Kinugawa for helping us identify and fix the security-related issues in this release.

Changelog
Full changelog: 3.5.0

Ajax
Do not execute scripts for unsuccessful HTTP responses (#4250, #4655, da3dd85b)
Overwrite s.contentType with content-type header value, if any (#4119, 065143c2)
Deprecate AJAX event aliases, inline event/alias into deprecated (7a3cf9c0)
Build
Resolve Travis config warnings (7506c9ca)
Enable ESLint one-var rule for var declarations in browser code (0fdfdd82)
Test the no-Sizzle build on Travis (362075ae)
Update .mailmap & AUTHORS.txt (19f2dcba)
Tests: Fix custom build tests, verify on Travis; name Travis jobs (d525ae34)
Lint the minified jQuery file as well (#3075, 37df5cdf)
Make Karma work in AMD mode (46c284b1)
Create a grunt custom:slim alias for the Slim build (4cbdc745)
Run tests on Travis only on browsers defined in the config (471b0043)
Run tests on Firefox ESR as well (0a73b94a)
Run tests on Node.js 13 in addition to 8, 10 & 12 (64c1fcc1)
Drop workarounds for Node.js 6 in Gruntfile.js (9f4204ec)
Run tests on Travis on FirefoxHeadless as well (ad3c2efa)
Require strict mode in Node.js scripts via ESLint (ac2da4e6)
Support jquery-release –dry-run flag (c7a5e1bd)
Stop copying src/core.js to dist on release (#4489, 279d2e97)
ESLint: forbid unused function parameters (d7e13f12)
Fix the regex parsing AMD var-modules (#4389) (36b59c96)
Core
Ajax: Align nonce & global with master, fix an AMD issue (22bf701f)
Fire iframe script in its context, add doc param in globalEval (#4518, 3dedc3f2)
Deprecate jQuery.trim (#4363, 56e73e0c)
Use Array.prototype.flat where supported (#4320, 2f666c1d)
Implement .even() & .odd() to replace POS :even & :odd (409cbda7)
CSS
Workaround buggy getComputedStyle on table rows in IE/Edge (#4490, 6d31477a)
Data
Event:Manipulation: Prevent collisions with Object.prototype (#3256, 413ff796)
Docs
Update links to EdgeHTML issues to go through Web Archive (d72faced)
Convert link to Homebrew from HTTP to HTTPS (ff5a43eb)
Effect
Fix a unnecessary conditional statement in .stop() (#4374, 30f5c6c3)
Event
Use only one focusin/out handler per matching window & document (#4652, 9e15d6b4)
Only attach events to objects that accept data – for real (#4397, f36f6abb)
Manipulation
Skip the select wrapper for option elements
Make jQuery.htmlPrefilter an identity function (1d61fd94)
Offset
Send px-ed strings to .css() (57038fae)
Selector
Update Sizzle from 2.3.4 to 2.3.5 (#4424, #4435, #4441, #4453, 04bf577e)
Make selector-native’s isXMLDoc recognize HTML-embedded SVG (2d9d6d5b)
Tests
Blacklist one focusin test in IE (1a4f10dd)
Pass a number of necessary done() calls to assert.async() (5ea844f6)
Make the support tests pass on Firefox 4x/5x/60 (f0d5ec62)
Skip a “width/height on a table row with phantom borders” test in Firefox (c79e1d5f)
Don’t test synchronous XHR on unload in Chrome (c5b48c8c)
Fix offset fractions tests in Chrome for Android (0c67da4b)
Move Android user agent detection above iOS, put Safari last (6276cb2e)
Make support tests accept Safari 13 & newer (8167327f)
update npo.js and include unminified source instead (3654bc83)
Traversing
Fix contents() on object elements with children in IE (90f78b9a)
Fix contents() on object elements with children (#4384, 42badf34)
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值