首页 > 其他 > 详细

008 BOM

时间:2019-08-01 09:40:46      阅读:70      评论:0      收藏:0      [点我收藏+]

一:说明

1.说明

  浏览器对象模型

  

2.顶级对象

  浏览器中的顶级对象是window

  页面中的顶级对象是document

  因此:

   变量属于window的,函数也是window的。

   就可以使用window.变量,window.函数。

 

3.window的另一个名字

  top=window

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6 </head>
 7 <body>
 8 <script>
 9     var name="tom";
10     console.log(top.name);
11 </script>
12 </body>
13 </html>

 

4.系统的对话框

  都不建议使用,一是外表都不同,影响加载。

  window.alert("mnmnmn")

  window.prompt("输入:");

  var result = window.confirm();  true或者false是返回值

 

二:加载事件

1.页面加载完成之后触发的事件

1 window.onload=function () {
2         
3 }

 

2.扩展事件

  事件关闭之前触发:onbeforeunload

  页面关闭后才触发:onunload

 

三:Location对象

1.说明

  是地址栏

  可以设置和获取URL

 

2.程序

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6 </head>
 7 <body>
 8     <script>
 9         console.log(window.location);
10     </script>
11 </body>
12 </html>

  效果:

  技术分享图片

 

3.示例

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>Title</title>
 6 </head>
 7 <body>
 8     <input type="button" value="显示" id="btn">
 9     <script>
10         console.log(window.location.hash);     //#,以及之后的内容
11         console.log(window.location.host);     //主机名及端口号
12         console.log(window.location.hostname);
13         console.log(window.location.pathname);
14         console.log(window.location.port);
15         console.log(window.location.protocol);
16         console.log(window.location.search); //搜索的内容
17 
18         onload=function () {
19             document.getElementById("btn").onclick=function () {
20                 location.href="https://www.baidu.com";     //属性:设置跳转的地址,有后退
21                 location.assign("https://www.baidu.com");  //方法,与上面的相同,有后退
22                 location.reload(); //刷新
23                 location.replace("https://www.baidu.com");  //没有后退,因为没有历史记录
24             }
25         }
26     </script>
27 </body>
28 </html>

 

 

 

 

 

 

 

 

 

 

  

  

008 BOM

原文:https://www.cnblogs.com/juncaoit/p/11280006.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!