javascript Window及document對象詳細(xì)整理
更新時間:2011年01月12日 00:11:00 作者:
注:頁面上元素name屬性以及JavaScript引用的名稱必須一致包括大小寫否則會提示你1個錯誤信息 引用的元素為空或者不是對象
一、Window對象
-------------------------------------------------- -------------------
對象屬性
window //窗戶自身
window.self //引用本窗戶window=window.self
window.name //為窗戶命名
window.defaultStatus //設(shè)定窗戶狀態(tài)欄信息
window.location //URL地址,配備布置這個屬性可以打開新的頁面
-------------------------------------------------- -------------------
對象方法
window.alert("text") //提示信息會話框
window.confirm("text") //確認(rèn)會話框
window.prompt("text") //要求鍵盤輸入會話框
window.setIntervel("action",time) //每一隔指定的時間(毫秒)就執(zhí)行一次操作
window.clearInterval() //清除時間配備布置作用就是終止輪回
window.setTimeout(action,time) //隔了指定的時間(毫秒)執(zhí)行一次操作
window.open() //打開新的窗戶
window.close() //關(guān)閉窗戶
-------------------------------------------------- -------------------
成員對象
window.event
window.document //見document對象詳解
window.history
window.screen
window.navigator
window.external
-------------------------------------------------- -------------------
window.history對象
window.history.length //瀏覽過的頁面數(shù)
history.back() //撤退退卻
history.forward() //進步
history.go(i) //前進或頭退到歷史記錄的第i個頁面
//i>0進步,i<0撤退退卻
-------------------------------------------------- -------------------
window.screen對象
window.screen.width //屏幕寬度
window.screen.height //屏幕高度
window.screen.colorDepth //屏幕色深
window.screen.availWidth //可用寬度
window.screen.availHeight //可用高度(除去任務(wù)欄的高度)
-------------------------------------------------- -------------------
window.external對象
window.external.AddFavorite("地址","標(biāo)題" ) //把網(wǎng)站新增到保藏夾
-------------------------------------------------- -------------------
window.navigator對象
window.navigator.appCodeName //瀏覽器代碼名
window.navigator.appName //瀏覽器步伐名
window.navigator.appMinorVersion //瀏覽器補釘版本
window.navigator.cpuClass //cpu類型 x86
window.navigator.platform //操作體系類型 win32
window.navigator.plugins
window.navigator.opsProfile
window.navigator.userProfile
window.navigator.systemLanguage //客戶體系語言 zh-cn簡體中文
window.navigator.userLanguage //用戶語言,同上
window.navigator.appVersion //瀏覽器版本(包括 體系版本)
window.navigator.userAgent
window.navigator.onLine //用戶否在線
window.navigator.cookieEnabled //瀏覽器是否撐持cookie
window.navigator.mimeTypes
==================================================
二、document對象
對象屬性:
document.title //設(shè)置文檔標(biāo)題等價于HTML的<title>標(biāo)簽
document.bgColor //設(shè)置頁面背景色
document.fgColor //設(shè)置前景色(文本顏色)
document.linkColor //未點擊過的鏈接顏色
document.alinkColor //激活鏈接(焦點在此鏈接上)的顏色
document.vlinkColor //已點擊過的鏈接顏色
document.URL //設(shè)置URL屬性從而在同一窗口打開另一網(wǎng)頁
document.fileCreatedDate //文件建立日期,只讀屬性
document.fileModifiedDate //文件修改日期,只讀屬性
document.fileSize //文件大小,只讀屬性
document.cookie //設(shè)置和讀出cookie
document.charset //設(shè)置字符集 簡體中文:gb2312
----------------------------
常用對象方法
document.write() //動態(tài)向頁面寫入內(nèi)容
document.createElement(Tag) //創(chuàng)建一個html標(biāo)簽對象
document.getElementById(ID) //獲得指定ID值的對象
document.getElementsByName(Name) //獲得指定Name值的對象
document.body.appendChild(oTag)
body-主體子對象
document.body //指定文檔主體的開始和結(jié)束等價于<body></body>
document.body.bgColor //設(shè)置或獲取對象后面的背景顏色
document.body.link //未點擊過的鏈接顏色
document.body.alink //激活鏈接(焦點在此鏈接上)的顏色
document.body.vlink //已點擊過的鏈接顏色
document.body.text //文本色
document.body.innerText //設(shè)置<body>...</body>之間的文本
document.body.innerHTML //設(shè)置<body>...</body>之間的HTML代碼
document.body.topMargin //頁面上邊距
document.body.leftMargin //頁面左邊距
document.body.rightMargin //頁面右邊距
document.body.bottomMargin //頁面下邊距
document.body.background //背景圖片
document.body.appendChild(oTag) //動態(tài)生成一個HTML對象
常用對象事件
document.body.onclick="func()" //鼠標(biāo)指針單擊對象是觸發(fā)
document.body.onmouseover="func()" //鼠標(biāo)指針移到對象時觸發(fā)
document.body.onmouseout="func()" //鼠標(biāo)指針移出對象時觸發(fā)
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é)議(http:)
document.location.search // ?號后的部分
常用對象事件
documeny.location.reload() //刷新網(wǎng)頁
document.location.reload(URL) //打開新的網(wǎng)頁
document.location.assign(URL) //打開新的網(wǎng)頁
document.location.replace(URL) //打開新的網(wǎng)頁
========================================================================
selection-選區(qū)子對象
document.selection
========================================================================
images集合(頁面中的圖象):
----------------------------
a)通過集合引用
document.images //對應(yīng)頁面上的<img>標(biāo)簽
document.images.length //對應(yīng)頁面上<img>標(biāo)簽的個數(shù)
document.images[0] //第1個<img>標(biāo)簽
document.images[i] //第i-1個<img>標(biāo)簽
----------------------------
b)通過nane屬性直接引用
<img name="oImage">
document.images.oImage //document.images.name屬性
----------------------------
c)引用圖片的src屬性
document.images.oImage.src //document.images.name屬性.src
----------------------------
d)創(chuàng)建一個圖象
var oImage
oImage = new Image()
document.images.oImage.src="1.jpg"
同時在頁面上建立一個<img>標(biāo)簽與之對應(yīng)就可以顯示
----------------------------
示例代碼(動態(tài)創(chuàng)建圖象):
<html>
<img name=oImage>
<script language="javascript">
var oImage
oImage = new Image()
document.images.oImage.src="1.jpg"
</script>
</html>
<html>
<script language="javascript">
oImage=document.caeateElement("IMG")
oImage.src="1.jpg"
</script>
-------------------------------------------------- -------------------
對象屬性
window //窗戶自身
window.self //引用本窗戶window=window.self
window.name //為窗戶命名
window.defaultStatus //設(shè)定窗戶狀態(tài)欄信息
window.location //URL地址,配備布置這個屬性可以打開新的頁面
-------------------------------------------------- -------------------
對象方法
window.alert("text") //提示信息會話框
window.confirm("text") //確認(rèn)會話框
window.prompt("text") //要求鍵盤輸入會話框
window.setIntervel("action",time) //每一隔指定的時間(毫秒)就執(zhí)行一次操作
window.clearInterval() //清除時間配備布置作用就是終止輪回
window.setTimeout(action,time) //隔了指定的時間(毫秒)執(zhí)行一次操作
window.open() //打開新的窗戶
window.close() //關(guān)閉窗戶
-------------------------------------------------- -------------------
成員對象
window.event
window.document //見document對象詳解
window.history
window.screen
window.navigator
window.external
-------------------------------------------------- -------------------
window.history對象
window.history.length //瀏覽過的頁面數(shù)
history.back() //撤退退卻
history.forward() //進步
history.go(i) //前進或頭退到歷史記錄的第i個頁面
//i>0進步,i<0撤退退卻
-------------------------------------------------- -------------------
window.screen對象
window.screen.width //屏幕寬度
window.screen.height //屏幕高度
window.screen.colorDepth //屏幕色深
window.screen.availWidth //可用寬度
window.screen.availHeight //可用高度(除去任務(wù)欄的高度)
-------------------------------------------------- -------------------
window.external對象
window.external.AddFavorite("地址","標(biāo)題" ) //把網(wǎng)站新增到保藏夾
-------------------------------------------------- -------------------
window.navigator對象
window.navigator.appCodeName //瀏覽器代碼名
window.navigator.appName //瀏覽器步伐名
window.navigator.appMinorVersion //瀏覽器補釘版本
window.navigator.cpuClass //cpu類型 x86
window.navigator.platform //操作體系類型 win32
window.navigator.plugins
window.navigator.opsProfile
window.navigator.userProfile
window.navigator.systemLanguage //客戶體系語言 zh-cn簡體中文
window.navigator.userLanguage //用戶語言,同上
window.navigator.appVersion //瀏覽器版本(包括 體系版本)
window.navigator.userAgent
window.navigator.onLine //用戶否在線
window.navigator.cookieEnabled //瀏覽器是否撐持cookie
window.navigator.mimeTypes
==================================================
二、document對象
對象屬性:
document.title //設(shè)置文檔標(biāo)題等價于HTML的<title>標(biāo)簽
document.bgColor //設(shè)置頁面背景色
document.fgColor //設(shè)置前景色(文本顏色)
document.linkColor //未點擊過的鏈接顏色
document.alinkColor //激活鏈接(焦點在此鏈接上)的顏色
document.vlinkColor //已點擊過的鏈接顏色
document.URL //設(shè)置URL屬性從而在同一窗口打開另一網(wǎng)頁
document.fileCreatedDate //文件建立日期,只讀屬性
document.fileModifiedDate //文件修改日期,只讀屬性
document.fileSize //文件大小,只讀屬性
document.cookie //設(shè)置和讀出cookie
document.charset //設(shè)置字符集 簡體中文:gb2312
----------------------------
常用對象方法
document.write() //動態(tài)向頁面寫入內(nèi)容
document.createElement(Tag) //創(chuàng)建一個html標(biāo)簽對象
document.getElementById(ID) //獲得指定ID值的對象
document.getElementsByName(Name) //獲得指定Name值的對象
document.body.appendChild(oTag)
body-主體子對象
document.body //指定文檔主體的開始和結(jié)束等價于<body></body>
document.body.bgColor //設(shè)置或獲取對象后面的背景顏色
document.body.link //未點擊過的鏈接顏色
document.body.alink //激活鏈接(焦點在此鏈接上)的顏色
document.body.vlink //已點擊過的鏈接顏色
document.body.text //文本色
document.body.innerText //設(shè)置<body>...</body>之間的文本
document.body.innerHTML //設(shè)置<body>...</body>之間的HTML代碼
document.body.topMargin //頁面上邊距
document.body.leftMargin //頁面左邊距
document.body.rightMargin //頁面右邊距
document.body.bottomMargin //頁面下邊距
document.body.background //背景圖片
document.body.appendChild(oTag) //動態(tài)生成一個HTML對象
常用對象事件
document.body.onclick="func()" //鼠標(biāo)指針單擊對象是觸發(fā)
document.body.onmouseover="func()" //鼠標(biāo)指針移到對象時觸發(fā)
document.body.onmouseout="func()" //鼠標(biāo)指針移出對象時觸發(fā)
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é)議(http:)
document.location.search // ?號后的部分
常用對象事件
documeny.location.reload() //刷新網(wǎng)頁
document.location.reload(URL) //打開新的網(wǎng)頁
document.location.assign(URL) //打開新的網(wǎng)頁
document.location.replace(URL) //打開新的網(wǎng)頁
========================================================================
selection-選區(qū)子對象
document.selection
========================================================================
images集合(頁面中的圖象):
----------------------------
a)通過集合引用
document.images //對應(yīng)頁面上的<img>標(biāo)簽
document.images.length //對應(yīng)頁面上<img>標(biāo)簽的個數(shù)
document.images[0] //第1個<img>標(biāo)簽
document.images[i] //第i-1個<img>標(biāo)簽
----------------------------
b)通過nane屬性直接引用
<img name="oImage">
document.images.oImage //document.images.name屬性
----------------------------
c)引用圖片的src屬性
document.images.oImage.src //document.images.name屬性.src
----------------------------
d)創(chuàng)建一個圖象
var oImage
oImage = new Image()
document.images.oImage.src="1.jpg"
同時在頁面上建立一個<img>標(biāo)簽與之對應(yīng)就可以顯示
----------------------------
示例代碼(動態(tài)創(chuàng)建圖象):
<html>
<img name=oImage>
<script language="javascript">
var oImage
oImage = new Image()
document.images.oImage.src="1.jpg"
</script>
</html>
<html>
<script language="javascript">
oImage=document.caeateElement("IMG")
oImage.src="1.jpg"
</script>
相關(guān)文章
在JavaScript應(yīng)用中使用RequireJS來實現(xiàn)延遲加載
這篇文章主要介紹了在JavaScript應(yīng)用中使用RequireJS來實現(xiàn)延遲加載,JavaScript是一款人氣JS庫,需要的朋友可以參考下2015-07-07
javascript instanceof 與typeof使用說明
instanceof和typeof都能用來判斷一個變量是否為空或是什么類型的變量。2010-01-01
javascript Function函數(shù)理解與實戰(zhàn)
小編給大家?guī)硪黄P(guān)于javascript的基礎(chǔ)教學(xué)內(nèi)容,關(guān)于Function函數(shù)的訓(xùn)練與理解,一起學(xué)習(xí)下吧。2017-12-12
Javascript學(xué)習(xí)筆記一 之 數(shù)據(jù)類型
在接觸每一門編程語言之前,首先明白我們程序設(shè)計要處理的是數(shù)據(jù),而數(shù)據(jù)又用數(shù)據(jù)類型將其區(qū)分。2010-12-12
Array.slice()與Array.splice()的返回值類型
Array.slice()與Array.splice()的返回值類型...2006-10-10

