大学生深陷校园贷溺亡:html网页中,如何让警告框弹出延时?

来源:百度文库 编辑:高校问答 时间:2024/04/19 10:40:48
我在编辑html网页,有一个按钮,点击按钮会马上弹出一个警告框。
我想实现的效果是,点击按钮2秒钟后再弹出警告框,应该怎么实现?
点击立即弹出的代码如下:
<input TYPE="button" VALUE="弹出警告框" ONCLICK="AlertButton()">
<script language="JavaScript">
<!--
function AlertButton(){window.alert("今天你喝了没有?:)");}
// -->
</script>

我知道有一个延时函数setTimeout() 但不知道在这里能不能用也不知道怎么用。
哪位高手给我解答一下啊!急!!

<input TYPE="button" VALUE="弹出警告框" ONCLICK="AlertButton()">
<script language="JavaScript">
<!--
function AlertButton(){
window.setTimeout("window.alert('今天你喝了没有?:)')",2000);
}
// -->
</script>

或者

<input TYPE="button" VALUE="弹出警告框" ONCLICK="window.setTimeout('AlertButton()',2000)">
<script language="JavaScript">
<!--
function AlertButton(){
window.alert("今天你喝了没有?:)");
}
// -->
</script>