【Java script問題集】2-1 ボタン押下時に、5秒おくれてアラート表示してみよう
2-1.html
<!DOCTYPE html>
<html lang="jp" dir="ltr">
<head>
<title>2-1</title>
<body>
<div id="shiritori">
<button id="btn">ボタン押下後、5秒後にアラート表示</button>
</div>
</body>
</html>
2-1.js
$(function(){
$("#btn").click(function(){
setTimeout('alert("Hello world!")', 5000);
});
});
実行結果(ボタン押下前)
実行結果(ボタン押下5秒後)