在我的网站上,我使用以下代码。它在jQuery 2.2.3中运行得很好。现在我想使用jQuery 3,但它似乎不起作用。你能帮我把这段代码重写成jQuery 3吗?香草js解决方案也将不胜感激。
$(document).ready(function () {
$('#preloading').load("loading.html", function () {
$(window).load(function () {
$('#preloading').fadeOut('slow');
});
});
});发布于 2017-01-16 09:15:43
您的问题在于,在jQuery 3.x中,load()方法仅用于通过AJAX请求检索内容,因此使用它作为事件处理程序是无效的。顺便提一下--在您使用2.x的原始代码中不需要它。
要解决这个问题,只需删除$(window).load()调用:
$(document).ready(function () {
$('#preloading').load("loading.html", function() {
$('#preloading').fadeOut('slow');
});
});发布于 2017-05-31 09:33:37
Lucas,您的代码已经废弃/删除了方法:
$(document).ready (https://jquery.com/upgrade-guide/3.0/#deprecated-document-ready-handlers-other-than-jquery-function).load() (https://jquery.com/upgrade-guide/3.0/#breaking-change-load-unload-and-error-removed)替换后:
$(function () {
$('#preloading').load("loading.html", function () {
$(window).on('load', function () {
$('#preloading').fadeOut('slow');
});
});
});https://stackoverflow.com/questions/41672826
复制相似问题