浅谈window对象和document对象

1、window:代表浏览器中一个打开的窗口。

(1)对象属性

① window.self 引用本窗口window==window.self

② window.name 为窗口名字

③ window.defaultStatus 窗户状态栏信息

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

(2)对象方法

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

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

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

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

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

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

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

⑧ window.close() 关闭窗口

(3)成员对象

① window.event

② window.document

③ Window.history

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

b. window.history.back() 后退

c. window.history.forward() 前进

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

④ Window.screen

a. window.screen.width 屏幕宽度

b. window.screen.height 屏幕高度

c. window.screen.colorDepth 屏幕色深

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

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

⑤ 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类型(数组)

 

2、document对象:代表整个HTML 文档,可用来访问页面中的所有元素。

(1)对象属性

① document.title                 文档标题,等价于HTML的<title>标签

② document.bgColor            页面背景色

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

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

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

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

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

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

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

⑩ document.fileSize              大小,只读属性

⑪ document.cookie                设置和读出cookie

⑫ document.charset               字符集

(2)对象方法

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

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

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

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

(3)body对象

① document.body                 文档主体开始和结束,等价于<body></body>

② document.body.bgColor          背景颜色

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

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

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

⑥ document.body.text        文本色

⑦ document.body.innerText      <body>...</body>之间的文本

⑧ document.body.innerHTML  <body>...</body>之间的HTML代码

⑨ document.body.topMargin 页面上边距

⑩ document.body.leftMargin      页面左边距

⑪ document.body.rightMargin   页面右边距

⑫ document.body.bottomMargin  页面下边距

⑬ document.body.background    背景

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

⑮ document.body.οnclick="func()"              鼠标指针单击对象是触发

⑯ document.body.οnmοuseοver="func()"    鼠标指针移到对象时触发

⑰ document.body.οnmοuseοut="func()"        鼠标指针移出对象时触发

(4)location-位置子对象

① document.location.hash  #号后的部分

② document.location.host        域名+端口号

③ document.location.hostname     域名

④ document.location.href          完整URL

⑤ document.location.pathname 目录部分

⑥ document.location.port     端口号

⑦ document.location.protocol    网络协议

⑧ document.location.search      ?号后的部分

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

① document.images                <img>标签

② document.images.length          <img>标签的个数

③ document.images[0]             第1个<img>标签           

④ document.images[i]          第i-1个<img>标签

 

  • 5
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值