您的位置:首页 > Web前端 > JavaScript

JavaScript的bom对象

2017-12-04 20:23 344 查看

js的bom对象

** bom:broswer object model: 浏览器对象模型

** 有哪些对象?

了解即可 navigator: 获取客户机的信息(浏览器的信息)*

- navigator.appName

- document.write(navigator.appName);

* **screen: 获取屏幕的信息

- document.write(screen.width);

document.write(“<br/>”);

document.write(screen.height);

* **location: 请求url地址

-href属性

* 获取到请求的url地址*

- document.write(location.href);



设置url地址

- 页面上安置一个按钮,按钮上绑定一个事件,当我点击这个按钮,页面可以跳转到另外一个页面

- location.href = “hello.html”;

** <input type=”button” value=”tiaozhuan” onclick=”href1();”/>

- 鼠标点击事件 onclick=”js的方法;”



* **history:请求的url的历史记录

- 创建三个页面

1、创建第一个页面 a.html 写一个超链接 到 b.html

2、创建b.html 超链接 到 c.html

3、创建c.html

- 到访问的上一个页面

history.back();

history.go(-1);

- 到访问的下一个页面

history.forward();

history.go(1);

* [b]window(*[/b])

* 窗口对象

* 顶层对象(所用的bom对象都是在window里面操作的)

** 方法(必须记住)

- window.alert() : 页面弹出一个框,显示内容

** 简写alert()

- confirm(): 确认框

- var flag = window.confirm(“显示的内容”);

-点击确定返回true,点击取消返回false

- prompt(): 输入的对话框

- window.prompt(“please input : “,”0”);

- window.prompt(“在显示的内容”,”输入框里面的默认值”);

- open() : 打开一个新的窗口

** open(“打开的新窗口的地址url”,”“,”窗口特征,比如窗口宽度和高度”)

- 创建一个按钮,点击这个按钮,打开一个新的窗口

- window.open(“hello.html”,”“,”width=200,height=100”);

- close(): 关闭窗口(浏览器兼容性比较差)

- window.close();

- 做定时器

** setInterval(“js代码”,毫秒数) 1秒=1000毫秒

- 表示每三秒,执行一次alert方法

window.setInterval(“alert(‘123’);”,3000);//注意格式

** setTimeout(“js代码”,毫秒数)

- 表示在毫秒数之后执行,但是只会执行一次

- 表示四秒之后执行js代码,只会执行一次

window.setTimeout(“alert(‘abc’);”,4000);

** clearInterval(): 清除setInterval设置的定时器

var id1 = setInterval(“alert(‘123’);”,3000);//通过setInterval会有一个返回值

clearInterval(id1);

** clearTimeout() : 清除setTimeout设置的定时器

var id2 = setTimeout(“alert(‘abc’);”,4000);

clearTimeout(id2);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: