我已成功设法使用setInterval函数在400毫秒后点击div.我的问题是它不断运行,我只需要执行一次的函数.快速搜索后,我发现clearInterval可以停止setInterval.我错误地使用了这个吗?closeAnimation函数正在点击执行.我在此页面上的代码之后对我的代码进行了建模:http://www.w3schools.com/jsref/met_win_setinterval.asp
function closeAnimation() {
setInterval(function(){hide()}, 400);
clearInterval(stopAnimation);
}
var stopAnimation = setInterval({hide()}, 400);
Run Code Online (Sandbox Code Playgroud)