JavaScript setTimeoutで指定した時間後に処理を実行する

環境
Google Chrome  115.0.5790.171(Official Build) (64 ビット)
Windows 11 Pro 64bit

構文
setTimeout(“関数名", ミリ秒);
setTimeout(functionRef, delay)
functionRef タイマーが満了した後に実行する関数。
delay 指定した関数やコードを実行する前に待つタイマーの時間をミリ秒 (1/1000 秒) 単位で指定します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<!DOCTYPE html>
<html>
<body>
<script>
setTimeout("funA()", 6000);
function funA() {
console.log('6秒経過処理')
}
</script>
</body>
</html>
<!DOCTYPE html> <html> <body> <script> setTimeout("funA()", 6000); function funA() { console.log('6秒経過処理') } </script> </body> </html>
<!DOCTYPE html>
<html>
<body>


<script>
setTimeout("funA()", 6000);

function funA() {    
  console.log('6秒経過処理')
}
</script>

</body>
</html>

実行結果
6秒経過後下記メッセージを出力します。
6秒経過処理

JavaScript

Posted by arkgame