我基本上是“创造”的基础上的信息完全来自#1以下功能不与警报(属性字符串)注册一个属性:jQuery的功能设置
function PreloadImageSources(arrayOfImageSources)
{
// call with PreloadImages(['src1', 'src2', etc])
var newImage = $('<img />');
$(arrayOfImageSources).each(function() {
/*
alert(this); // OK
*/
newImage.get(0).src = this; // explicit iteration because of .each
});
/*
alert(newImage.get(0).src); // still OK!
*/
// return the new array of img objects, each with their .src set
return $('<img />');
}
两个警报显示函数内正确的字符串。但是,一旦我从函数返回,
var shutterImg = PreloadImageSources([options.shutterImgSrc]) [0];
alert(shutterImg.src);
该警报显示什么,如果它不存在,尽管我刚分配它的函数里面的事实。
我缺少什么基本内核?
有显示如何预加载图像中的多个其他答案:[图像预加载JavaScript的支持事件(http://stackoverflow.com/questions/8264528/image-preloader-javascript-that-supports-events/8265310#8265310),[是否有可能在渲染前在缓存中插入图像](http://stackoverflow.com/questions/8831345/is-it-possible-to-insert-images-in-cache-before-rendering/8831405#8831405)和[有没有办法将图像加载到用户的缓存异步?](http://stackoverflow.com/questions/8450068/is-there-a-way-to-load-images-to-users -cache-asynchronously/8450190#8450190) – jfriend00
'return $('
');'返回一个带有一个新的图像对象的jQuery对象,它没有'.src'属性,这就是为什么你的alert没有显示一个src网址。我不知道你为什么回来,因为它没有任何用处,并且与你预先加载的图片没有任何关系。 –
jfriend00
谢谢大家......谢谢你,我发现我的错误... .attr('src',this)是正确的,但.attr('src')=这不是 –