jQuery 3.0 $(window).load(function(){});

标签 jquery

今天发布了 jQuery 3.0,由于某种原因,以下代码不再在我的网站上运行:

$(window).load(function() {});

任何人都可以建议我如何修复此问题或在加载/everything/时激活的替代方案吗?

最佳答案

阅读自breaking-change-load-unload-and-error-removed :

Breaking change: .load(), .unload(), and .error() removed

These methods are shortcuts for event operations, but had several API limitations. The event .load() method conflicted with the ajax .load() method. The .error() method could not be used with window.onerror because of the way the DOM method is defined. If you need to attach events by these names, use the .on() method, e.g. change $("img").load(fn) to $(img).on("load", fn).

因此,您需要更改:

$(window).load(function() {});

至:

$(window).on("load", function (e) {})

关于jQuery 3.0 $(window).load(function(){});,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37751179/

相关文章:

javascript - Twitter 如何给我发推文的回调?

javascript - 如何根据目标父元素重命名可排序的嵌套元素?

jquery - Dojo 1.6 中相当于 jQuery(html) 的是什么?

c# - ASP.NET中如何获取登录用户信息

javascript - jQuery 如果在 x 分钟内没有单击类,则执行某些操作

jquery - JQuery从1.51升级到2后出现语法错误

php - 自定义 WordPress 小部件,带有媒体上传按钮,在每个小部件上插入相同的图像

javascript - 全日历标签顺序在 Chrome 浏览器中不同

javascript - 函数发生在 onclick 事件之前

javascript - 将鼠标悬停在图像效果上