博主:DongJiang
码龄:7年
等级:LV.22级
内容:316
今日访问:2312
访问总量:5936
博客简介:学习与分享
博客创建时间:2018-04-12
博客主页 立即前往
赞助位
成为赞助商

什么是window对象? 什么是document对象?

来源: 2024-05-19 17:37:55 播报

window对象是指浏览器打开的窗口。是 JavaScript 中的全局对象,在浏览器环境中始终存在且可直接访问。

document对象是Document对象(HTML 文档对象)的一个只读引用,window对象的一个属性。

window对象

1、对象属性

1)window.self 引用本窗口window==window.self

2)window.name 为窗口名字

3)window.defaultStatus 窗户状态栏信息

4)window.location URL地址,设置该属性可打开新的页面

2、对象方法

1)window.alert("text") 提示信息会话框

2)window.confirm("text") 确认会话框

3)window.prompt("text") 键盘输入会话框

4)window.setIntervel(func, time) 每隔指定时间(毫秒)执行一次操作

5)window.clearInterval() 清除时间间隔

6)window.setTimeout(action,time) 等待指定时间(毫秒)后再执行操作

7)window.open() 打开新的窗口

8)window.close() 关闭窗口

3、成员对象

1)window.event

2)window.document

3)Window.history

a. window.history.length 浏览过的页面数

b. window.history.back() 后退

c. window.history.forward() 前进

d. window.history.go(i) 前进或后退i个页面(i>0前进,i<0后退)

4)Window.screen

a. window.screen.width 屏幕宽度

b. window.screen.height 屏幕高度

c. window.screen.colorDepth 屏幕色深

d. window.screen.availWidth 屏幕可用宽度

e. window.screen.availHeight 屏幕可用高度(除去任务栏的高度)

5)Window.navigator

a. window.navigator.appCodeName 浏览器代码名

b. window.navigator.appName 浏览器名

c. window.navigator.platform 运行浏览器的操作系统平台

d. window.navigator.appVersion 浏览器的平台和版本

e. window.navigator.userAgent 由客户机发送服务器的user-agent 头部的值

f. window.navigator.cookieEnabled 浏览器是否启用cookie

g. window.navigator.appMinorVersion 浏览器补丁版本

h. window.navigator.cpuClass cpu类型

i. Window.navigator.plugins 插件标识

j. window.navigator.userProfile 用户的个人信息

k. window.navigator.systemLanguage 客户体系语言

l. window.navigator.userLanguage 用户语言

m. window.navigator.onLine 用户是否在线

n. window.navigator.mimeTypes MIME类型(数组)

document对象

1、对象属性

1)document.title 文档标题,等价于HTML的 标签

2)document.bgColor 页面背景色

3)document.fgColor 前景色(文本颜色)

4)document.linkColor 未点击过的链接颜色

5)document.alinkColor 激活链接(焦点在此链接上)的颜色

6)document.vlinkColor 已点击过的链接颜色

7)document.URL 在同一窗口打开另一网页

8)document.fileCreatedDate 文件建立日期,只读属性

9)document.fileModifiedDate 文件修改日期,只读属性

10)document.fileSize 大小,只读属性

11)document.cookie 设置和读出cookie

12)document.charset 字符集

2、对象方法

1)document.write() 动态向页面写入内容

2)document.createElement(tag) 创建指定标签的元素

3)document.getElementById(id) 获得指定id值的元素

4)document.getElementsByName(name) 获得指定Name值的元素

3、body对象

1)document.body 文档主体开始和结束,等价于

2)document.body.bgColor 背景颜色

3)document.body.link 未点击过的链接颜色

4)document.body.alink 激活链接(焦点在此链接上)的颜色

5)document.body.vlink 已点击过的链接颜色

6)document.body.text 文本色

7)document.body.innerText ...之间的文本

8)document.body.innerHTML ...之间的HTML代码

9)document.body.topMargin 页面上边距

10)document.body.leftMargin 页面左边距

11)document.body.rightMargin 页面右边距

12)document.body.bottomMargin 页面下边距

13)document.body.background 背景

14)document.body.appendChild(oTag) 添加DOM对象

15)document.body.onclick="func()" 鼠标指针单击对象是触发

16)document.body.onmouseover="func()" 鼠标指针移到对象时触发

17)document.body.onmouseout="func()" 鼠标指针移出对象时触发

4、location-位置子对象

1)document.location.hash #号后的部分

2)document.location.host 域名 端口号

3)document.location.hostname 域名

4)document.location.href 完整URL

5)document.location.pathname 目录部分

6)document.location.port 端口号

7)document.location.protocol 网络协议

8)document.location.search ?号后的部分

5、通过集合引用(以images集合为例,forms集合等类似)

1)document.images 标签

2)document.images.length 标签的个数

3)document.images[0] 第1个标签

4)document.images[i] 第i-1个标签

原文出处:
版权声明:本文来源地址若非本站均为转载,若侵害到您的权利,请及时联系我们,我们会在第一时间进行处理。