使用jQuery下载图像 [英] Download image using jquery

查看:80
本文介绍了使用jQuery下载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表单加载中,我使用jquery下载图像,并且当用户单击任何按钮时,我正在div中显示该图像.但只有第一次图像需要时间才能看到.如果图像是在表单加载时下载的,那么当我通过jquery显示该图像时,我认为它不应再次下载,并且应该很快可见.

in my form load i download a image using jquery and when user click on any button then i am showing that image in my div. but only first time image is taking time to visible. if image is downloaded at form load so when i am showing that image through jquery then i think it should not download again and it should be visible very quickly.

 var _images = ['/Images/ajax-loader.gif'];
   $.each(_images, function (e) {
       $(new Image()).load(function () {
           //alert($(this).attr('src') + 'has loaded!');
       }).attr('src', this);
   });

通过上述例程,我将在jquery的帮助下以表格加载方式下载图像.

through the above routine i am downloading image at form load with the help of jquery.

所以当我在用户单击下面的按钮时显示该图像时

so when i am showing that image when user click on button like below one

                   $('#loader').html('<table border="0" style="width:auto"><tr><td valign="middle">Wait...</td><td valign="top"><img height="20px" width="20px" src="/images/ajax-loader.gif" border="0" /></td></tr></table>');

loader是我的div

loader is my div

,因此该映像不应再次下载,而应从客户端计算机上显示. 因此,请指导我代码中有什么问题,即图像是在窗体加载时下载的,尽管它是第一次重新加载.请帮忙...谢谢

so the image should not download again rather it should show from the client machine. so please guide me what is wrong in my code that image is download at form load and inspite of that it is again loading for the first time. please help...thanks

推荐答案

您正在预加载/Images/ajax-loader.gif并使用/images/ajax-loader.gif(请注意I/i).我怀疑浏览器将它们视为不同的图片.

You're pre-loading /Images/ajax-loader.gif and using /images/ajax-loader.gif (note I/i). I suspect the browser regards them as different pictures.

这篇关于使用jQuery下载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆