首頁技術(shù)文章正文

什么是 Window 對象? 什么是 Document 對象?

更新時間:2021-01-22 來源:黑馬程序員 瀏覽量:

1577370495235_學(xué)IT就到黑馬程序員.gif

1)window:代表瀏覽器中一個打開的窗口。
(1)對象屬性
① window.self 引用本窗口window==window.self
② window.name 為窗口名字
③ window.defaultStatus 窗戶狀態(tài)欄信息
④ window.location URL地址,設(shè)置該屬性可打開新的頁面
(2)對象方法
① window.alert("text") 提示信息會話框
② window.confirm("text") 確認(rèn)會話框
③ window.prompt("text") 鍵盤輸入會話框
④ window.setIntervel(func, time) 每隔指定時間(毫秒)執(zhí)行一次操作
⑤ window.clearInterval() 清除時間間隔
⑥ window.setTimeout(action,time) 等待指定時間(毫秒)后再執(zhí)行操作
⑦ window.open() 打開新的窗口
⑧ window.close() 關(guān)閉窗口
(3)成員對象
① window.event
② window.document
③ Window.history
a. window.history.length 瀏覽過的頁面數(shù)
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 屏幕可用高度(除去任務(wù)欄的高度)
⑤ Window.navigator
a. window.navigator.appCodeName 瀏覽器代碼名
b. window.navigator.appName 瀏覽器名
c. window.navigator.platform 運行瀏覽器的操作系統(tǒng)平臺
d. window.navigator.appVersion 瀏覽器的平臺和版本
e. window.navigator.userAgent 由客戶機發(fā)送服務(wù)器的user-agent 頭部的值
f. window.navigator.cookieEnabled 瀏覽器是否啟用cookie
g. window.navigator.appMinorVersion 瀏覽器補丁版本
h. window.navigator.cpuClass cpu類型
i. Window.navigator.plugins 插件標(biāo)識
j. window.navigator.userProfile 用戶的個人信息
k. window.navigator.systemLanguage 客戶體系語言
l. window.navigator.userLanguage 用戶語言
m. window.navigator.onLine 用戶是否在線
n. window.navigator.mimeTypes MIME類型(數(shù)組)

1611296963884_Document 對象.gif

2)document對象:代表整個HTML 文檔,可用來訪問頁面中的所有元素。
(1)對象屬性
① document.title 文檔標(biāo)題,等價于HTML的
標(biāo)簽
② document.bgColor 頁面背景色
③ document.fgColor 前景色(文本顏色)
④ document.linkColor 未點擊過的鏈接顏色
⑤ document.alinkColor 激活鏈接(焦點在此鏈接上)的顏色
⑥ document.vlinkColor 已點擊過的鏈接顏色
⑦ document.URL 在同一窗口打開另一網(wǎng)頁
⑧ document.fileCreatedDate 文件建立日期,只讀屬性
⑨ document.fileModifiedDate 文件修改日期,只讀屬性
⑩ document.fileSize 大小,只讀屬性
? document.cookie 設(shè)置和讀出cookie
? document.charset 字符集
(2)對象方法
① document.write() 動態(tài)向頁面寫入內(nèi)容
② document.createElement(tag) 創(chuàng)建指定標(biāo)簽的元素
③ document.getElementById(id) 獲得指定id值的元素
④ document.getElementsByName(name) 獲得指定Name值的元素
(3)body對象
① document.body 文檔主體開始和結(jié)束,等價于
② document.body.bgColor 背景顏色
③ document.body.link 未點擊過的鏈接顏色
④ document.body.alink 激活鏈接(焦點在此鏈接上)的顏色
⑤ document.body.vlink 已點擊過的鏈接顏色
⑥ document.body.text 文本色
⑦ document.body.innerText
...之間的文本
⑧ document.body.innerHTML
...之間的HTML代碼
⑨ document.body.topMargin 頁面上邊距
⑩ document.body.leftMargin 頁面左邊距
? document.body.rightMargin 頁面右邊距
? document.body.bottomMargin 頁面下邊距
? document.body.background 背景
? document.body.appendChild(oTag) 添加DOM對象
? document.body.onclick="func()" 鼠標(biāo)指針單擊對象是觸發(fā)
? document.body.onmouseover="func()" 鼠標(biāo)指針移到對象時觸發(fā)
? document.body.onmouseout="func()" 鼠標(biāo)指針移出對象時觸發(fā)
(4)location-位置子對象
① document.location.hash #號后的部分
② document.location.host 域名+端口號
③ document.location.hostname 域名
④ document.location.href 完整URL
⑤ document.location.pathname 目錄部分
⑥ document.location.port 端口號
⑦ document.location.protocol 網(wǎng)絡(luò)協(xié)議
⑧ document.location.search ?號后的部分
(5)通過集合引用(以images集合為例,forms集合等類似)
① document.images 標(biāo)簽
② document.images.length 標(biāo)簽的個數(shù)
③ document.images[0] 第1個標(biāo)簽
④ document.images[i] 第i-1個標(biāo)簽



猜你喜歡:

如何理解面向?qū)ο蟮姆庋b、繼承和多態(tài)?

怎樣給移動端頁面設(shè)置不同于PC端的樣式?

CSS是什么意思?CSS的全稱是什么?

黑馬程序員web前端培訓(xùn)課程

分享到:
在線咨詢 我要報名
和我們在線交談!