I have a small problem with the following script:

$(document).load('img', function(){
     alert('images have loaded');
})

The alert will pop up after all images have loaded, which is correct. However, the 'img' generates a 404 warning in the console.

GET http://www.website.com/img 404 (Not Found) 
有帮助吗?

解决方案

You're doing that wrong, right now you're trying to load data with ajax from the URL img, as that's what the load() method does, and that's why you're getting the 404.

Using a delegated event handler like that makes no sense, if you're trying to wait for all external resources (as in images etc.) to load, use window.onload

$(window).on('load', function(){
     alert('images have loaded');
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top