我想在我的网站上延迟一段时间。到目前为止,我已经建立了一个睡眠功能,可以冻结我的系统数秒。但有了这个,我无法访问网站的用户界面。
我的代码:
<html>
<head>
<title></title>
</head>
<body>
<button onclick="on_click()">Button-1</button>
<button onclick="console.log('BYE');">Button-2</button>
<script>
function on_click()
{
sleep(15000);
console.log("HI");
}
function sleep(delay)
{
var start = new Date().getTime();
while (new Date().getTime() < start + delay);
}
</script>
</body>
</html>
所以每当我点击
Button-1
,我必须等待15秒才能单击
Button-2
. 我要我的程序允许我点击
按钮-1
它应该等待15秒,并在控制台上显示“嗨”。也允许我点击
按钮-2
. 请帮忙。谢谢