jquery-4
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesejQuery 4.0 Migration
jQuery 4.0 迁移指南
Status: Production Ready
Last Updated: 2026-01-25
Dependencies: None
Latest Versions: jquery@4.0.0, jquery-migrate@4.0.2
状态:可用于生产环境
最后更新:2026-01-25
依赖项:无
最新版本:jquery@4.0.0、jquery-migrate@4.0.2
Quick Start (5 Minutes)
快速开始(5分钟)
1. Add jQuery Migrate Plugin for Safe Testing
1. 添加jQuery Migrate插件以安全测试
Before upgrading, add the migrate plugin to identify compatibility issues:
html
<!-- Development: Shows console warnings for deprecated features -->
<script src="https://code.jquery.com/jquery-4.0.0.js"></script>
<script src="https://code.jquery.com/jquery-migrate-4.0.2.js"></script>Why this matters:
- Logs specific warnings when deprecated/removed features execute
- Identifies code that needs updating before it breaks
- Provides backward compatibility shims during transition
在升级前,添加迁移插件以识别兼容性问题:
html
<!-- Development: Shows console warnings for deprecated features -->
<script src="https://code.jquery.com/jquery-4.0.0.js"></script>
<script src="https://code.jquery.com/jquery-migrate-4.0.2.js"></script>重要性:
- 当执行已弃用/已移除的功能时,会在控制台记录特定警告
- 在代码崩溃前识别需要更新的部分
- 在过渡期间提供向后兼容的垫片
2. Install via npm (if using build tools)
2. 通过npm安装(若使用构建工具)
bash
npm install jquery@4.0.0bash
npm install jquery@4.0.0Or with migrate plugin for testing
Or with migrate plugin for testing
npm install jquery@4.0.0 jquery-migrate@4.0.2
undefinednpm install jquery@4.0.0 jquery-migrate@4.0.2
undefined3. Check for Breaking Changes
3. 检查重大变更
Run your application and check console for migrate plugin warnings. Each warning indicates code that needs updating.
运行应用程序并检查控制台中的迁移插件警告。每个警告都表示有代码需要更新。
Breaking Changes Reference
重大变更参考
Removed jQuery Utility Functions
已移除的jQuery工具函数
These functions were deprecated and are now removed. Use native JavaScript equivalents:
| Removed | Native Replacement |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| Custom function (see below) |
| |
camelCase replacement:
javascript
// Native replacement for $.camelCase
function camelCase(str) {
return str.replace(/-([a-z])/g, (match, letter) => letter.toUpperCase());
}这些函数已被弃用并现已移除,请使用原生JavaScript替代方案:
| 已移除函数 | 原生替代方案 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| 自定义函数(见下文) |
| |
camelCase替代方案:
javascript
// Native replacement for $.camelCase
function camelCase(str) {
return str.replace(/-([a-z])/g, (match, letter) => letter.toUpperCase());
}Removed Prototype Methods
已移除的原型方法
Three internal array methods removed from jQuery objects:
javascript
// OLD - No longer works in jQuery 4.0
$elems.push(elem);
$elems.sort(compareFn);
$elems.splice(index, count);
// NEW - Use array methods with call/apply
[].push.call($elems, elem);
[].sort.call($elems, compareFn);
[].splice.call($elems, index, count);
// Or convert to array first
const arr = $.makeArray($elems);
arr.push(elem);jQuery对象中移除了三个内部数组方法:
javascript
// OLD - No longer works in jQuery 4.0
$elems.push(elem);
$elems.sort(compareFn);
$elems.splice(index, count);
// NEW - Use array methods with call/apply
[].push.call($elems, elem);
[].sort.call($elems, compareFn);
[].splice.call($elems, index, count);
// Or convert to array first
const arr = $.makeArray($elems);
arr.push(elem);Focus/Blur Event Order Changed
焦点/失焦事件顺序变更
jQuery 4.0 follows the W3C specification for focus event order:
javascript
// jQuery 3.x order (non-standard):
// focusout → blur → focusin → focus
// jQuery 4.0 order (W3C standard):
// blur → focusout → focus → focusinImpact: If your code depends on specific event ordering, test thoroughly.
javascript
// Example: code that may need adjustment
$input.on('blur focusout focus focusin', function(e) {
console.log(e.type); // Order changed in 4.0
});jQuery 4.0遵循W3C规范的焦点事件顺序:
javascript
// jQuery 3.x order (non-standard):
// focusout → blur → focusin → focus
// jQuery 4.0 order (W3C standard):
// blur → focusout → focus → focusin影响:如果您的代码依赖特定的事件顺序,请彻底测试。
javascript
// Example: code that may need adjustment
$input.on('blur focusout focus focusin', function(e) {
console.log(e.type); // Order changed in 4.0
});Removed from Slim Build
精简版构建中移除的内容
The slim build () no longer includes:
jquery-4.0.0.slim.min.js- Deferreds and Callbacks (use native Promises instead)
- AJAX functionality
- Animation effects
javascript
// If using slim build, replace Deferreds with Promises
// OLD - Deferred
const deferred = $.Deferred();
deferred.resolve(value);
deferred.promise();
// NEW - Native Promise
const promise = new Promise((resolve, reject) => {
resolve(value);
});精简版构建()不再包含:
jquery-4.0.0.slim.min.js- Deferreds和Callbacks(请改用原生Promises)
- AJAX功能
- 动画效果
javascript
// If using slim build, replace Deferreds with Promises
// OLD - Deferred
const deferred = $.Deferred();
deferred.resolve(value);
deferred.promise();
// NEW - Native Promise
const promise = new Promise((resolve, reject) => {
resolve(value);
});toggleClass Changes
toggleClass变更
The and signatures are removed:
toggleClass(boolean)toggleClass(undefined)javascript
// OLD - No longer works
$elem.toggleClass(true); // Added all classes
$elem.toggleClass(false); // Removed all classes
// NEW - Be explicit
$elem.addClass('class1 class2'); // Add classes
$elem.removeClass('class1 class2'); // Remove classes
// Or use toggleClass with class names
$elem.toggleClass('active', true); // Force add
$elem.toggleClass('active', false); // Force removetoggleClass(boolean)toggleClass(undefined)javascript
// OLD - No longer works
$elem.toggleClass(true); // Added all classes
$elem.toggleClass(false); // Removed all classes
// NEW - Be explicit
$elem.addClass('class1 class2'); // Add classes
$elem.removeClass('class1 class2'); // Remove classes
// Or use toggleClass with class names
$elem.toggleClass('active', true); // Force add
$elem.toggleClass('active', false); // Force removeAJAX Script Execution
AJAX脚本执行
Scripts fetched via AJAX no longer auto-execute unless dataType is specified:
javascript
// OLD - Scripts auto-executed
$.get('script.js');
// NEW - Must specify dataType for auto-execution
$.get({
url: 'script.js',
dataType: 'script'
});
// Or use $.getScript (still works)
$.getScript('script.js');通过AJAX获取的脚本不再自动执行,除非指定dataType:
javascript
// OLD - Scripts auto-executed
$.get('script.js');
// NEW - Must specify dataType for auto-execution
$.get({
url: 'script.js',
dataType: 'script'
});
// Or use $.getScript (still works)
$.getScript('script.js');Removed CSS Properties
已移除的CSS属性
| Removed | Notes |
|---|---|
| Removed - define locally if needed |
| No longer needed - vendor prefixes obsolete |
| Removed - requestAnimationFrame handles this |
| 已移除属性 | 说明 |
|---|---|
| 已移除 - 如有需要请在本地定义 |
| 不再需要 - 浏览器前缀已过时 |
| 已移除 - requestAnimationFrame会处理此功能 |
WordPress-Specific Migration
WordPress专属迁移指南
1. Check WordPress jQuery Version
1. 检查WordPress中的jQuery版本
bash
undefinedbash
undefinedCheck current jQuery version in WordPress
Check current jQuery version in WordPress
wp eval "echo wp_scripts()->registered['jquery-core']->ver;"
undefinedwp eval "echo wp_scripts()->registered['jquery-core']->ver;"
undefined2. WordPress jQuery Migration Path
2. WordPress jQuery迁移路径
WordPress themes/plugins should:
php
// Dequeue old jQuery and enqueue 4.0 (testing only)
function upgrade_jquery_for_testing() {
if (!is_admin()) {
wp_deregister_script('jquery-core');
wp_deregister_script('jquery');
wp_register_script('jquery-core',
'https://code.jquery.com/jquery-4.0.0.min.js',
array(), '4.0.0', true);
wp_register_script('jquery', false, array('jquery-core'), '4.0.0', true);
// Add migrate plugin for debugging
wp_enqueue_script('jquery-migrate',
'https://code.jquery.com/jquery-migrate-4.0.2.min.js',
array('jquery'), '4.0.2', true);
}
}
add_action('wp_enqueue_scripts', 'upgrade_jquery_for_testing', 1);WordPress主题/插件应使用以下代码:
php
// Dequeue old jQuery and enqueue 4.0 (testing only)
function upgrade_jquery_for_testing() {
if (!is_admin()) {
wp_deregister_script('jquery-core');
wp_deregister_script('jquery');
wp_register_script('jquery-core',
'https://code.jquery.com/jquery-4.0.0.min.js',
array(), '4.0.0', true);
wp_register_script('jquery', false, array('jquery-core'), '4.0.0', true);
// Add migrate plugin for debugging
wp_enqueue_script('jquery-migrate',
'https://code.jquery.com/jquery-migrate-4.0.2.min.js',
array('jquery'), '4.0.2', true);
}
}
add_action('wp_enqueue_scripts', 'upgrade_jquery_for_testing', 1);3. Common WordPress Plugin Issues
3. WordPress插件常见问题
Many WordPress plugins use removed jQuery methods:
javascript
// Common pattern in older plugins - BROKEN in 4.0
if ($.isArray(data)) { ... }
var json = $.parseJSON(response);
var cleaned = $.trim(userInput);
// Fix: Update to native methods
if (Array.isArray(data)) { ... }
var json = JSON.parse(response);
var cleaned = userInput.trim();许多WordPress插件使用已移除的jQuery方法:
javascript
// Common pattern in older plugins - BROKEN in 4.0
if ($.isArray(data)) { ... }
var json = $.parseJSON(response);
var cleaned = $.trim(userInput);
// Fix: Update to native methods
if (Array.isArray(data)) { ... }
var json = JSON.parse(response);
var cleaned = userInput.trim();Migration Patterns
迁移模式
Pattern 1: Type Checking Migration
模式1:类型检查迁移
javascript
// OLD jQuery type checking
if ($.type(value) === 'array') { ... }
if ($.type(value) === 'function') { ... }
if ($.type(value) === 'object') { ... }
if ($.type(value) === 'string') { ... }
if ($.type(value) === 'number') { ... }
// NEW Native type checking
if (Array.isArray(value)) { ... }
if (typeof value === 'function') { ... }
if (value !== null && typeof value === 'object' && !Array.isArray(value)) { ... }
if (typeof value === 'string') { ... }
if (typeof value === 'number') { ... }javascript
// OLD jQuery type checking
if ($.type(value) === 'array') { ... }
if ($.type(value) === 'function') { ... }
if ($.type(value) === 'object') { ... }
if ($.type(value) === 'string') { ... }
if ($.type(value) === 'number') { ... }
// NEW Native type checking
if (Array.isArray(value)) { ... }
if (typeof value === 'function') { ... }
if (value !== null && typeof value === 'object' && !Array.isArray(value)) { ... }
if (typeof value === 'string') { ... }
if (typeof value === 'number') { ... }Pattern 2: Utility Function Polyfills
模式2:工具函数Polyfill
If you need quick compatibility without changing all code:
javascript
// Polyfill removed methods (temporary migration aid)
if (typeof $.isArray === 'undefined') {
$.isArray = Array.isArray;
}
if (typeof $.parseJSON === 'undefined') {
$.parseJSON = JSON.parse;
}
if (typeof $.trim === 'undefined') {
$.trim = function(str) {
return str == null ? '' : String.prototype.trim.call(str);
};
}
if (typeof $.now === 'undefined') {
$.now = Date.now;
}
if (typeof $.isFunction === 'undefined') {
$.isFunction = function(fn) {
return typeof fn === 'function';
};
}
if (typeof $.isNumeric === 'undefined') {
$.isNumeric = function(val) {
return !isNaN(parseFloat(val)) && isFinite(val);
};
}CRITICAL: This is a temporary measure. Update your code to use native methods.
如果您需要快速兼容而不修改所有代码:
javascript
// Polyfill removed methods (temporary migration aid)
if (typeof $.isArray === 'undefined') {
$.isArray = Array.isArray;
}
if (typeof $.parseJSON === 'undefined') {
$.parseJSON = JSON.parse;
}
if (typeof $.trim === 'undefined') {
$.trim = function(str) {
return str == null ? '' : String.prototype.trim.call(str);
};
}
if (typeof $.now === 'undefined') {
$.now = Date.now;
}
if (typeof $.isFunction === 'undefined') {
$.isFunction = function(fn) {
return typeof fn === 'function';
};
}
if (typeof $.isNumeric === 'undefined') {
$.isNumeric = function(val) {
return !isNaN(parseFloat(val)) && isFinite(val);
};
}重要提示:这只是临时措施。请更新您的代码以使用原生方法。
Pattern 3: ES Modules Import
模式3:ES模块导入
jQuery 4.0 supports ES modules:
javascript
// ES Module import (new in 4.0)
import $ from 'jquery';
// Or with named export
import { $ } from 'jquery';
// In package.json, ensure module resolution
{
"type": "module"
}jQuery 4.0支持ES模块:
javascript
// ES Module import (new in 4.0)
import $ from 'jquery';
// Or with named export
import { $ } from 'jquery';
// In package.json, ensure module resolution
{
"type": "module"
}Pattern 4: Trusted Types Compliance
模式4:Trusted Types合规
For CSP with Trusted Types:
javascript
// jQuery 4.0 accepts TrustedHTML in DOM manipulation
import DOMPurify from 'dompurify';
// Create trusted HTML
const clean = DOMPurify.sanitize(untrustedHTML, {RETURN_TRUSTED_TYPE: true});
// Safe to use with jQuery 4.0
$('#container').html(clean);对于启用Trusted Types的CSP:
javascript
// jQuery 4.0 accepts TrustedHTML in DOM manipulation
import DOMPurify from 'dompurify';
// Create trusted HTML
const clean = DOMPurify.sanitize(untrustedHTML, {RETURN_TRUSTED_TYPE: true});
// Safe to use with jQuery 4.0
$('#container').html(clean);Critical Rules
关键规则
Always Do
务必执行
- Add jquery-migrate plugin BEFORE upgrading production
- Test focus/blur event handlers thoroughly
- Replace removed utility functions with native equivalents
- Specify for AJAX script loading
dataType: 'script' - Use ES module imports when possible for modern projects
- 在升级生产环境前添加jquery-migrate插件
- 彻底测试焦点/失焦事件处理程序
- 用原生替代方案替换已移除的工具函数
- 对于AJAX脚本加载,指定
dataType: 'script' - 尽可能为现代项目使用ES模块导入
Never Do
切勿执行
- Upgrade production without testing with migrate plugin first
- Assume WordPress plugins are jQuery 4.0 compatible
- Use slim build if you need AJAX or Deferreds
- Rely on - use native type checking
$.type() - Use signature
toggleClass(boolean)
- 未使用迁移插件测试就直接升级生产环境
- 假设WordPress插件兼容jQuery 4.0
- 如果需要AJAX或Deferreds,仍使用精简版构建
- 依赖- 使用原生类型检查
$.type() - 使用调用签名
toggleClass(boolean)
Known Issues Prevention
已知问题预防
This skill prevents 8 documented issues:
本指南可预防8个已记录的问题:
Issue #1: $.isArray is not a function
问题1:$.isArray is not a function
Error:
Source: https://github.com/jquery/jquery/issues/5411
Why It Happens: Method removed in jQuery 4.0
Prevention: Use instead
TypeError: $.isArray is not a functionArray.isArray()错误:
来源:https://github.com/jquery/jquery/issues/5411
原因:该方法在jQuery 4.0中已被移除
预防方案:改用
TypeError: $.isArray is not a functionArray.isArray()Issue #2: $.parseJSON is not a function
问题2:$.parseJSON is not a function
Error:
Source: https://jquery.com/upgrade-guide/4.0/
Why It Happens: Deprecated since 3.0, removed in 4.0
Prevention: Use instead
TypeError: $.parseJSON is not a functionJSON.parse()错误:
来源:https://jquery.com/upgrade-guide/4.0/
原因:自3.0版本起被弃用,4.0版本中移除
预防方案:改用
TypeError: $.parseJSON is not a functionJSON.parse()Issue #3: $.trim is not a function
问题3:$.trim is not a function
Error:
Source: https://jquery.com/upgrade-guide/4.0/
Why It Happens: Native String.prototype.trim available everywhere
Prevention: Use or
TypeError: $.trim is not a functionstr.trim()String.prototype.trim.call(str)错误:
来源:https://jquery.com/upgrade-guide/4.0/
原因:原生String.prototype.trim已在所有环境中可用
预防方案:改用或
TypeError: $.trim is not a functionstr.trim()String.prototype.trim.call(str)Issue #4: Focus events fire in wrong order
问题4:焦点事件触发顺序错误
Error: Unexpected behavior in form validation
Source: https://blog.jquery.com/2026/01/17/jquery-4-0-0/
Why It Happens: jQuery 4.0 follows W3C spec, not legacy order
Prevention: Test and update event handlers that depend on order
错误:表单验证行为异常
来源:https://blog.jquery.com/2026/01/17/jquery-4-0-0/
原因:jQuery 4.0遵循W3C规范,而非旧版顺序
预防方案:测试并更新依赖事件顺序的处理程序
Issue #5: Deferreds undefined in slim build
问题5:精简版构建中Deferreds未定义
Error:
Source: https://blog.jquery.com/2026/01/17/jquery-4-0-0/
Why It Happens: Removed from slim build in 4.0
Prevention: Use full build or native Promises
TypeError: $.Deferred is not a function错误:
来源:https://blog.jquery.com/2026/01/17/jquery-4-0-0/
原因:4.0版本的精简版构建中已移除
预防方案:使用完整版构建或原生Promises
TypeError: $.Deferred is not a functionIssue #6: Scripts not executing from AJAX
问题6:AJAX加载的脚本未执行
Error: Script loaded but not executed
Source: https://jquery.com/upgrade-guide/4.0/
Why It Happens: Auto-execution disabled without explicit dataType
Prevention: Add to AJAX options
dataType: 'script'错误:脚本已加载但未执行
来源:https://jquery.com/upgrade-guide/4.0/
原因:未显式指定dataType时自动执行已禁用
预防方案:在AJAX选项中添加
dataType: 'script'Issue #7: toggleClass not working
问题7:toggleClass无法工作
Error: has no effect
Source: https://jquery.com/upgrade-guide/4.0/
Why It Happens: Boolean signature removed
Prevention: Use addClass/removeClass or toggleClass with class names
toggleClass(true)错误:无效果
来源:https://jquery.com/upgrade-guide/4.0/
原因:布尔类型的调用签名已被移除
预防方案:使用addClass/removeClass或带类名的toggleClass
toggleClass(true)Issue #8: WordPress plugin conflicts
问题8:WordPress插件冲突
Error: Various "is not a function" errors
Source: Common in WordPress ecosystem
Why It Happens: Plugins using removed jQuery methods
Prevention: Audit plugins with jquery-migrate before upgrading
错误:各种“is not a function”错误
来源:WordPress生态系统中常见
原因:插件使用了已移除的jQuery方法
预防方案:在升级前使用jquery-migrate审核插件
Browser Support
浏览器支持
Supported in jQuery 4.0
jQuery 4.0支持的浏览器
- Chrome (last 3 versions)
- Firefox (last 2 versions + ESR)
- Safari (last 3 versions)
- Edge (Chromium-based)
- iOS Safari (last 3 versions)
- Android Chrome (last 3 versions)
- Chrome(最新3个版本)
- Firefox(最新2个版本 + ESR)
- Safari(最新3个版本)
- Edge(基于Chromium)
- iOS Safari(最新3个版本)
- Android Chrome(最新3个版本)
Dropped Support
已放弃支持的浏览器
- IE 10 and older (IE 11 supported until jQuery 5.0)
- Edge Legacy (EdgeHTML)
- Very old mobile browsers
- IE 10及更早版本(IE 11将被支持至jQuery 5.0)
- Edge Legacy(EdgeHTML内核)
- 非常老旧的移动浏览器
Slim vs Full Build Comparison
精简版与完整版构建对比
| Feature | Full Build | Slim Build |
|---|---|---|
| Size (gzipped) | ~27.5k | ~19.5k |
| DOM Manipulation | Yes | Yes |
| Events | Yes | Yes |
| AJAX | Yes | No |
| Effects/Animation | Yes | No |
| Deferreds | Yes | No |
| Callbacks | Yes | No |
Use slim build when: Static sites, no AJAX needs, using native fetch/Promises
Use full build when: WordPress, AJAX-heavy apps, need $.animate or Deferreds
| 功能 | 完整版构建 | 精简版构建 |
|---|---|---|
| 大小(gzip压缩后) | ~27.5k | ~19.5k |
| DOM操作 | 是 | 是 |
| 事件处理 | 是 | 是 |
| AJAX | 是 | 否 |
| 效果/动画 | 是 | 否 |
| Deferreds | 是 | 否 |
| Callbacks | 是 | 否 |
使用精简版构建的场景:静态站点、无需AJAX、使用原生fetch/Promises
使用完整版构建的场景:WordPress、AJAX密集型应用、需要$.animate或Deferreds
Migration Checklist
迁移检查清单
- Add jquery-migrate@4.0.2 to development
- Run full site test, check console for warnings
- Replace $.isArray() with Array.isArray()
- Replace $.parseJSON() with JSON.parse()
- Replace $.trim() with str.trim()
- Replace $.now() with Date.now()
- Replace $.type() with native type checking
- Replace $.isFunction() with typeof check
- Replace $.isNumeric() with isNaN/isFinite check
- Update toggleClass(boolean) usage
- Add dataType to script AJAX calls
- Test focus/blur event order
- Audit WordPress plugins if applicable
- Remove jquery-migrate after fixing all issues
- Upgrade to jquery@4.0.0 in production
- 在开发环境中添加jquery-migrate@4.0.2
- 运行全站测试,检查控制台中的警告
- 用Array.isArray()替换$.isArray()
- 用JSON.parse()替换$.parseJSON()
- 用str.trim()替换$.trim()
- 用Date.now()替换$.now()
- 用原生类型检查替换$.type()
- 用typeof检查替换$.isFunction()
- 用isNaN/isFinite检查替换$.isNumeric()
- 更新toggleClass(boolean)的用法
- 为脚本AJAX调用添加dataType
- 测试焦点/失焦事件顺序
- 若适用,审核WordPress插件
- 修复所有问题后移除jquery-migrate
- 在生产环境中升级至jquery@4.0.0
Official Documentation
官方文档
- jQuery 4.0.0 Release: https://blog.jquery.com/2026/01/17/jquery-4-0-0/
- Upgrade Guide: https://jquery.com/upgrade-guide/4.0/
- jQuery Migrate Plugin: https://github.com/jquery/jquery-migrate
- API Documentation: https://api.jquery.com/
- npm Package: https://www.npmjs.com/package/jquery
- jQuery 4.0.0发布说明:https://blog.jquery.com/2026/01/17/jquery-4-0-0/
- 升级指南:https://jquery.com/upgrade-guide/4.0/
- jQuery Migrate插件:https://github.com/jquery/jquery-migrate
- API文档:https://api.jquery.com/
- npm包:https://www.npmjs.com/package/jquery
Package Versions (Verified 2026-01-25)
已验证的包版本(2026-01-25)
json
{
"dependencies": {
"jquery": "^4.0.0"
},
"devDependencies": {
"jquery-migrate": "^4.0.2"
}
}json
{
"dependencies": {
"jquery": "^4.0.0"
},
"devDependencies": {
"jquery-migrate": "^4.0.2"
}
}Troubleshooting
故障排除
Problem: WordPress admin breaks after jQuery upgrade
问题:升级jQuery后WordPress后台崩溃
Solution: Only upgrade frontend jQuery. Admin uses its own version. Use conditional logic to avoid affecting wp-admin.
解决方案:仅升级前端的jQuery。后台使用独立版本。使用条件逻辑避免影响wp-admin。
Problem: Third-party plugins stop working
问题:第三方插件停止工作
Solution: Keep jquery-migrate loaded until plugins are updated. Check plugin changelogs for jQuery 4.0 compatibility updates.
解决方案:在插件更新前保留jquery-migrate加载。检查插件更新日志以确认是否兼容jQuery 4.0。
Problem: AJAX requests work but scripts don't execute
问题:AJAX请求正常但脚本未执行
Solution: Add to $.ajax options or use $.getScript() for script loading.
dataType: 'script'解决方案:在$.ajax选项中添加,或使用$.getScript()加载脚本。
dataType: 'script'Problem: Form validation fires at wrong times
问题:表单验证在错误时机触发
Solution: Review focus/blur/focusin/focusout handlers. jQuery 4.0 fires: blur → focusout → focus → focusin (W3C order).
Questions? Issues?
- Check console for jquery-migrate warnings
- Review upgrade guide: https://jquery.com/upgrade-guide/4.0/
- Check jQuery GitHub issues: https://github.com/jquery/jquery/issues
解决方案:检查blur/focusout/focus/focusin处理程序。jQuery 4.0的触发顺序为:blur → focusout → focus → focusin(W3C标准顺序)。
有疑问?遇到问题?
- 检查控制台中的jquery-migrate警告
- 查看升级指南:https://jquery.com/upgrade-guide/4.0/
- 查看jQuery GitHub问题:https://github.com/jquery/jquery/issues