Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个设置 src 属性的图像。
我想更换图像,但与服务器的连接速度很慢,加载新图像所需的时间也不容忽视。
是否有可能创建内部图像对象,在其上设置“onLoadListener”类型,加载图像,然后将其设置为原始图像 src 属性?
您可以像这样在 JavaScript 中预加载图像...
myImage = new Image(); myImage.onload = function () { alert("Loaded"); }; myImage.src = "logo.gif";
您可以将逻辑放在页面上弹出图像而不是警报。