<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Window对象</title>
</head>
<body>
<input id="openBtn" type="button" value="打开窗口">
<input id="closeBtn" type="button" value="关闭已打开的窗口">
<script>
/*
* Window 窗口对象
* 1.创建
* 2.方法
* 1.与弹出框有关的方法:
* alert() 显示带有一段消息和一个确认按钮的警告框。
* confirm() 显示带有一段消息以及确认按钮和取消按钮的对话框
* *如果用户按点击确定按钮,则方法返回true
* *如果用户点击取消按钮,则方法返回false
* prompt() 显示可提升用户输入的对话框
* *返回值是获取用户输入的值
* 2.与打开关闭有关的方法
* * close()关闭浏览器窗口
* * 谁调用我,我关谁
* * open()打开一个新的浏览器窗口
* * 返回一个新的Window对象
* 3.与定时器有关的方法
* setTimeout() 在指定的毫秒值后调用
* *参数
* 1.js代码或者方法对象
* 2.毫秒值
* * 返回值 : 唯一标识,用于取消定时器
* clearTimeout() 停止计时器
* setInterval() 按照指定周期(毫秒值)循环执行
* clearInterval() 取消循环定时器
*
* 3.属性
* 1.获取其他BOM对象
* history
* location
* Navigator
* Screen
* 2.获取DOM对象
* document
* 4.特点
* * Window对象不需要创建就可以直接使用 window使用
* window.方法名();
* window引用可以省略
* 方法名();
* 如 window.alert("hello");
* 可以写为 alert("hello");
*
* */
// window.alert("hello");
// alert("hello啊");
// var flag=confirm("您确定要退出吗?");
// if (flag){
// //退出操作
// alert("滚吧!");
// }else{
// //提升 手别抖
// alert("没事别乱点!");
// }
// //输入框
// var result=prompt("请输入用户名");
// alert(result);
// //打开新窗口
var openBtn=document.getElementById("openBtn");
// var newWindow;
// openBtn.οnclick=function () {
// //打开新窗口
// newWindow=open("https://www.baidu.com");
// };
// //关闭新窗口
// var closeBtn=document.getElementById("closeBtn");
// closeBtn.οnclick=function () {
// //关闭新窗口
// newWindow.close();
// }
// //一次性定时器
// // 2000毫秒(2秒)后 弹出提示框
// // setTimeout("fun2()",2000);
// //效果相同
// var id=setTimeout(fun2,1000);
// //取消定时器
// clearTimeout(id);
// function fun2() {
// alert('boom');
// }
// //循环定时器
// var id2=setInterval(fun2,2000);
// //取消循环定时器
// clearTimeout(id2);
// //获取history对象 以下两者效果相同
// var h1=window.history;
// var h2=history;
// alert(h1);
// alert(h2);
//以下两者效果相同
var openBtn=window.document.getElementById("openBtn");
alert(openBtn);
document.getElementById("")
</script>
</body>
</html>
前端技术——Window对象
最新推荐文章于 2024-05-29 19:02:09 发布