一段时间后启动功能

Start function after a time

本文关键字:功能 启动 一段时间      更新时间:2023-09-26

我如何在一段时间后启动函数,对于 exampl e:

<script>
function alert()
{
alert("Execute alert after 5 seconds");
}
</script>

alert();
我需要内部函数在 5 秒后

告诉执行,我该怎么做,我需要这个控件内部函数没有在其他函数或外部,例如警报函数内部的控件在 5 秒后启动函数

在此时间之后,必须最终执行该函数

谢谢的问候

使用 JavaScript 的 setTimeout 函数。

例如

setTimeout(function(){ alert("Hello World!"); }, 5000)

(参数是函数和执行前的毫秒)