Jquery .Load Image,如何检查图像是否已经加载到浏览器中?
我编写了一个简单的脚本来将图像加载到主查看器中。 非常简单,点击缩略图 - 获取图库 ID 和图像 ID。 将它们传递给 .load,加载新内容。
目前,如果您单击拇指,则会加载图像,如果您再次单击同一个拇指,它会再次调用该图像,我不希望这样。我希望能够检查图像是否已加载到浏览器缓存中,如果是,则不执行 .load
感谢您阅读本文,任何帮助将不胜感激。
$('#thumb_list li a').click(function(){
var gallery_id = $(this).attr('gallery');
var image_id = $(this).attr('rel');
$("#image_container")
.load("inc_photos.cfm?gallery_id=" + gallery_id + "&image_id=" + image_id,
function(){
});
return false;
});
I wrote a simple script to load the image in to the main viewer.
Its very simple, click thumbnail - grab the gallery id and the image id..
pass these in to the .load, new content is loaded.
At the moment if you click a thumb the image is loaded, and if you click the same thumb again it calls the image again, I don't want this. I want to be able to check if the image is already loaded in the browser cache and if so to not execute the .load
Thanks for reading this, any help would be appreciated.
$('#thumb_list li a').click(function(){
var gallery_id = $(this).attr('gallery');
var image_id = $(this).attr('rel');
$("#image_container")
.load("inc_photos.cfm?gallery_id=" + gallery_id + "&image_id=" + image_id,
function(){
});
return false;
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做几件事。
首先,如果您不希望在尝试加载图像后再次单击图像,则可以简单地从图像中删除单击。
但是,如果您想使用相同的单击方法执行其他操作,那么您可能需要添加一个标志来检查它是否已经加载。如果您遇到问题,可以在 2 个地方执行此操作。
如果您想避免任何重复的网络流量,也可以通过单击执行此操作:
There's a couple of things you can do.
First, you can simply remove the click even from the image if you don't want it to be able to be clicked again after it tries to load.
However, if you want to do something else with the same click method, then you might want to add a flag to check if it has already been loaded. You can do this in 2 places if you're having problems with it.
You can also do it on click if you want to avoid any duplicate network traffic: