gpt4 book ai didi

javascript - jQuery 更改 img src 并且不显示旧的

转载 作者:行者123 更新时间:2023-11-28 07:09:52 24 4
gpt4 key购买 nike

我正在使用 jQuery 替换部分图像 src 路径。它工作完美,但在显示新图像源之前仍然渲染旧图像。我想知道是否可以使用 .hide() 和 .show() 来防止旧图像渲染。

$(document).ready(function() {
$(".gallery img").each(function() {
$(this).attr("src", function(a, b) {
return b.replace("s72-c", "s190-c")
})
})
});

图像 URL 结构:

旧图片网址:http://www.example.com/s72-c/sample.jpg

新图片网址:http://www.example.com/s190-c/sample.jpg

最佳答案

迭代前hide()和迭代内show()

$(document).ready(function() {
$(".gallery img").hide().each(function() {
$(this).attr("src", function(a, b) {
return b.replace("s72-c", "s190-c")
});
$(this).show();
})
});

关于javascript - jQuery 更改 img src 并且不显示旧的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31406836/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com