<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>js的window对象</title>
<!--BOM浏览器对象模型:是规范浏览器对js语言的支持(js调用浏览器本身的功能
BOM的具体实现是window对象
window对象使用学习:
1:window对象不用new,直接进行使用即可,类似Math的使用方式,window关键字可省略不写
2:框体方法
alert:警告框,提示一个警告信息,没有返回值
confirm:确认框,提示用户选择一项操作(确认/取消)
prompt:提示框,提示某个信息的录入或者收集 ,点击确定返回当前用户录入的数据,默认返回空字符串
点击取消返回null
3:定时和间隔执行方法
定时执行:setTimeout:指定的事件后执行指定的函数
参数1:函数对象
参数2:时间,单位毫秒。
返回值:返回当前定时器的id
setInterval:每间隔指定的事件执行指定的函数
参数1:函数对象
参数2:时间,单位毫秒。
返回值:返回当前间隔期的id
clearTimeout:用来停止指定的定时器
参数:定时器的id
clearInterval:用来停止指定的间隔器
参数:间隔器的id
<!--声明Js代码域-->
<script type="text/javascript">
//框体方法学习
//警告框
//可以省略window直接alert
function testAlert(){
window.alert("我是警告框");
var a=window.alert("我是警告框");
alert(a);//undefined,无返回值
}
//确认框
function testConfirm(){
window.confirm("你确定要删除吗");
// var flag=window.confirm("你确定要删除吗");
// if(flag){
//
// }
// alert(flag);//确认返回true,取消返回false
}
//提示框
function testPromt(){
// window.prompt("请输入昵称");
var str=window.prompt("请输入昵称");
alert(str);//确认返回录入的字符串,取消返回null
}
var idi;
var ids;
//设置定时
function testSetTimeout(){
idi=window.setTimeout(function(){
alert("我是定时执行");
},3000);
}
//间隔执行
function testSetInterval(){
ids=window.setInterval(function(){
alert("我是间隔执行");
},2000);
}
//停止当前的定时方法
function testclearTimeout(){
window.clearTimeout(idi);
}
function testclearInterval(){
window.clearInterval(ids);
}
</script>
</head>
<body>
<h3>windows对象学习</h3><hr />
<br />
<input type="button" name="" id="" value="测试警告框" onclick="testAlert();" />
<input type="button" name="" id="" value="测试确认框" onclick="testConfirm();"/>
<input type="button" name="" id="" value="测试提示框" onclick="testPromt();" />
<hr />
<input type="button" name="" id="" value="测试setTimeout--定时执行" onclick="testSetTimeout();"/>
<input type="button" name="" id="" value="测试setInterval--定时执行" onclick="testSetInterval();"/>
<input type="button" name="" id="" value="测试clearTimeout--停止指定的定时器" onclick="testclearTimeout();"/>
<input type="button" name="" id="" value="测试clearTimeout--停止指定的间隔器" onclick="testclearInterval()"/>
</body>
</html>