使用JQuery预加载动态添加的图像

我将一些图像添加到Page_Load()事件中的数据库div。将鼠标悬停在其中一个黑白图像上时,会看到彩色图像。我想预先加载彩色图像,但我遇到了问题。我当前的代码循环遍历所有图像,并添加以下内容:
<script type="text/javascript">
<!-- 
$(document).ready(function() { 
    $("<img />").attr("src", "%s").load(function(){ 
        $("body").append($(this)); 
    }); 
});
--></script>
RegisterClientScriptBock
,其中
%s
是图像的路径。我尝试过,无需将其附加到身体上,但似乎都没有效果。从我所看到的,这似乎是预加载图像的方式,但我对其他建议持开放态度。我有问题因为我在飞行中这样做吗? 谢谢。     
已邀请:
你有没有想过创建一个绝对定位-10000px左边和顶部,高度/宽度1px,然后用html抛出所有图像的div?我不确定为什么你需要为这个使用js。     
也许这会有所帮助? http://www.yourhtmlsource.com/images/preloading.html
<script type="text/javascript">
<!-- hide from non JavaScript Browsers

Image1= new Image(150,20)
Image1.src = "pic1.gif"

Image2 = new Image(10,30)
Image2.src = "pic2.gif"

Image3 = new Image(72,125)
Image3.src = "pic3.gif"

// End Hiding -->
</script>
Image1 = new Image是为图像设置新脚本效果的第一步 (150,20)分别是该图像的宽度和高度 Image1.src =“pic1.gif”给出了图像的来源。     

要回复问题请先登录注册