我想同时显示一个元素和一个隐藏一个元素,在页面加载 2 秒后,我知道下面的代码不正确,但我只是用它来帮助理解我试图实现的逻辑。
delay(2000).$('#customer_contact').hide().$('#customer_contact_edit_cont').show();
如何最好地编写此逻辑?
除了语法问题之外,delay()
函数旨在延迟计划在jQuery的fx
队列上运行的动画发生。
如果要延迟动画之外发生的动作,则可以使用setTimeout()
,如下所示:
setTimeout(function() {
$('#customer_contact').hide();
$('#customer_contact_edit_cont').show();
}, 2000);
您应该使用setTimeout
函数。
setTimeout(
function(){
//Do something
}, 5000);
这里5000
以毫秒为单位的时间。(1 sec = 1000 ms
(