gpt4 book ai didi

javascript - 如何在 jQuery 中显示内容之前显示 setTimeout 图像?

转载 作者:太空宇宙 更新时间:2023-11-03 21:17:33 26 4
gpt4 key购买 nike

我有一个带有 on.click(function() {} 的按钮。点击函数内部是一个 setTimeout( function() {},它将显示来自外部 html 文件的内容。

<button type="button" class="btn btn-primary choose-iphone-btn">Jet Black</button>

$(function() {

$('.choose-iphone-btn').click(function() {

setTimeout( function() {

$.get('iphone-checkout.html')
.success(function(data) {
$('.iphone-pre-order-sales-content-info').html(data);
});

}, 3000);

});

});

我要展示

<img src="images/default.gif" /> 

3 秒后显示 iphone-checkout.html。

感谢任何帮助。

最佳答案

创建一个类来显示/隐藏图像。最初将其设置为 display:none

然后使用jquery addClass & removeClass方法显示和隐藏图片

CSS

.displayNone{
display:none
}

HTML

// added id & class to image tag
<img id="myImage" class="displayNone" src="images/default.gif" />

JS

$('.choose-iphone-btn').click(function() {
// removing the class to display the image
$("#myImage").removeClass("displayNone");
setTimeout( function() {

$.get('iphone-checkout.html')
.success(function(data) {
$('.iphone-pre-order-sales-content-info').html(data);
// adding class back on to hide mage on success of ajax
$("#myImage").addClass("displayNone");
});

}, 3000);

});

关于javascript - 如何在 jQuery 中显示内容之前显示 setTimeout 图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40837331/

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