<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>window对象的使用</title>
<!--
作者:李瑞琦
时间:2017-08-23
描述:
-->
<script type="text/javascript">
function testAlert(){
window.alert("我是警告框");
}
function testConfirm(){
var flag = window.confirm("你确定要退出吗");
}
function testPrompt(){
var flag = window.prompt("请输入昵称");
}
//定时执行
//定义全局变量记录线程id
var id;
var num;
//定时执行
function testTimeOut(){
id = window.setTimeout(function(){
alert("定时执行");
},2000);
}
//结束定时执行的线程
function clearTimeOut(){
window.clearTimeout(id);
}
//间隔执行
function testInterval(){
num = window.setInterval(function(){
alert("间隔执行")
},3000);
}
//结束间隔执行的线程
function clearInterval(){
window.clearInterval(num);
}
</script>
</head>
<body>
<h3>window对象的使用</h3>
<hr />
<input type="button" id="" name="" value="testAlert" onclick="testAlert()" />
<input type="button" id="" name="" value="testConfirm" onclick="testConfirm()" />
<input type="button" id="" name="" value="testPrompt" onclick="testPrompt()" />
<hr />
<input type="button" id="" name="" value="testTimeout" onclick="testTimeOut()" />
<input type="button" id="" name="" value="testClearTimeout" onclick="clearTimeOut()" />
<input type="button" id="" name="" value="testInterval" onclick="testInterval()" />
<input type="button" id="" name="" value="clearInterval" onclick="clearInterval()" />
</body>
</html>
JS中window对象的使用
最新推荐文章于 2025-07-17 21:00:12 发布