定时器和BOM
<body>
<input type="button" id="btn" value="按钮"/>
<input type="button" id="btn_" value="停止定时器"/>
<script>
/*
* javascript分三个部分
* 1.ECMAScript标准----基本语法
* 2.DOM----Document Object Model 文档对象模型,操作页面元素
* 3.BOM----Brower Object Model 浏览器对象模型,操作浏览器
*
* 浏览器中有个顶级对象:window
* 页面中顶级对象:document
* 页面中所有的内容都属于浏览器的,页面中的内容也是window的
*/
window.function(){
document.getElementById("btn").onclick=function(){
alert("页面加载事件,所有内容加载完毕后点击按钮触发");
}
}
// function(){
// document.getElementById("btn").onclick=function(){
// alert("这种也可以");
// }
//
// }
console.log(window.navigator.platform);//判断浏览器所在的系统平台类型
console.log(window.navigator.userAgent)//判断是什么浏览器类型
//BOM中的定时器
var timeId=setInterval(function(){//页面加载完毕后每过一秒就执行一次函数,返回一个id
alert("每过一秒执行一次这个函数");
},1000);
document.getElementById("btn_").onclick=function(){//停止定时器
window.clearInterval(timeId);
}
//一次性定时器
my$("btn_1").onclick=function(){
var timeId=window.setTimeout(function(){
alert("一次性定时器");
},2000)
// window.clearTimeout(timeId); 要来清理定时器
}
</script>
</body>