gpt4 book ai didi

javascript - 将变量传递给 setTimeout()

转载 作者:行者123 更新时间:2023-11-28 13:01:47 25 4
gpt4 key购买 nike

我想这样做:

var whatever = myfunction;
var time = 200;
setTimeout(whatever, time);

function myfunction() {
//do something
}

它不起作用,我不确定为什么

更好的例子:这是html网页:

<div id="example1" class="example-card" style="visibility: hidden;"></div>
<div id="example2" class="example-card" style="visibility: hidden;"></div>

这里是JSJS:

function example1() {
$("#example1").css('visibility', 'visible');
}
function example2() {
$("#example2").css('visibility', 'visible');
}

$(window).on("load", function(){
var time = 0;
$('.example-card').each(function() {
var exampleId = this.id;
setTimeout(exampleId, time);
time = time + 200;
});
});

谢谢

最佳答案

var whatever = myfunction;
var time = 2000;
setTimeout(whatever, time);

function myfunction() {
alert("hi");
}

关于javascript - 将变量传递给 setTimeout(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49772626/

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