$(document).ready(function() {
function loadSlide(url, zIndex, initLeft){
slide = $("<img />").attr("src", url).on("load", function() {
if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) {
console.log("broken image!");
} else {
$("#my_slider").append(slide);
slide.css({
"z-index": zIndex,
"left": initLeft
});
}
});
}
loadSlide("img/man_slide1.png", 100, "0vw");
loadSlide("img/man_slide2.png", 99, "0vw");
});
我无法用头围住这个问题。正如你所看到的,我希望多次调用相同的函数来加载多个图像。但只有最后一个加载在我的浏览器中(并在Inspector中检查)。使用相同的功能加载其他图像卸载另一个图像
我在做什么错?
这:'$(“”)'是错误的。它应该是'$(“img”)'。 –
我知道你的意思,我测试了它,但现在没有创建img标签。这就是为什么它是'$(“”)' –