Document對象內(nèi)容集合(比較全)
更新時間:2010年09月06日 12:04:37 作者:
這個是腳本之家從網(wǎng)上收集的比較全的Document對象內(nèi)容集合,Document對象是js編寫中經(jīng)常用到的對象。了解它方便以后的學(xué)習(xí)。
document 文擋對象 - JavaScript腳本語言描述
———————————————————————
注:頁面上元素name屬性和JavaScript引用的名稱必須一致包括大小寫
否則會提示你一個錯誤信息 “引用的元素為空或者不是對象\\\\\”
———————————————————————
對象屬性
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)就可以顯示
———————————————————————-
forms集合(頁面中的表單)
a)通過集合引用
document.forms //對應(yīng)頁面上的form標(biāo)簽
document.forms.length //對應(yīng)頁面上/formform標(biāo)簽的個數(shù)
document.forms[0] //第1個/formform標(biāo)簽
document.forms[i] //第i-1個/formform標(biāo)簽
document.forms[i].length //第i-1個/formform中的控件數(shù)
document.forms[i].elements[j] //第i-1個/formform中第j-1個控件
b)通過標(biāo)簽name屬性直接引用
/formform name=”Myform”>input name=”myctrl”/>/form
document.Myform.myctrl //document.表單名.控件名
c)訪問表單的屬性
document.forms[i].name //對應(yīng)form name>屬性
document.forms[i].action //對應(yīng)/formform action>屬性
document.forms[i].encoding //對應(yīng)/formform enctype>屬性
document.forms[i].target //對應(yīng)/formform target>屬性
document.forms[i].appendChild(oTag) //動態(tài)插入一個控件
document.all.oDiv //引用圖層oDiv
document.all.oDiv.style.display=”" //圖層設(shè)置為可視
document.all.oDiv.style.display=”none” //圖層設(shè)置為隱藏
document.getElementId(”oDiv”) //通過getElementId引用對象
document.getElementId(”oDiv”).style=”"
document.getElementId(”oDiv”).display=”none”
/*document.all表示document中所有對象的集合
只有ie支持此屬性,因此也用來判斷瀏覽器的種類*/
圖層對象的4個屬性
document.getElementById(”ID”).innerText //動態(tài)輸出文本
document.getElementById(”ID”).innerHTML //動態(tài)輸出HTML
document.getElementById(”ID”).outerText //同innerText
document.getElementById(”ID”).outerHTML //同innerHTML
———————————————————————
注:頁面上元素name屬性和JavaScript引用的名稱必須一致包括大小寫
否則會提示你一個錯誤信息 “引用的元素為空或者不是對象\\\\\”
———————————————————————
對象屬性
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)就可以顯示
———————————————————————-
forms集合(頁面中的表單)
a)通過集合引用
document.forms //對應(yīng)頁面上的form標(biāo)簽
document.forms.length //對應(yīng)頁面上/formform標(biāo)簽的個數(shù)
document.forms[0] //第1個/formform標(biāo)簽
document.forms[i] //第i-1個/formform標(biāo)簽
document.forms[i].length //第i-1個/formform中的控件數(shù)
document.forms[i].elements[j] //第i-1個/formform中第j-1個控件
b)通過標(biāo)簽name屬性直接引用
/formform name=”Myform”>input name=”myctrl”/>/form
document.Myform.myctrl //document.表單名.控件名
c)訪問表單的屬性
document.forms[i].name //對應(yīng)form name>屬性
document.forms[i].action //對應(yīng)/formform action>屬性
document.forms[i].encoding //對應(yīng)/formform enctype>屬性
document.forms[i].target //對應(yīng)/formform target>屬性
document.forms[i].appendChild(oTag) //動態(tài)插入一個控件
document.all.oDiv //引用圖層oDiv
document.all.oDiv.style.display=”" //圖層設(shè)置為可視
document.all.oDiv.style.display=”none” //圖層設(shè)置為隱藏
document.getElementId(”oDiv”) //通過getElementId引用對象
document.getElementId(”oDiv”).style=”"
document.getElementId(”oDiv”).display=”none”
/*document.all表示document中所有對象的集合
只有ie支持此屬性,因此也用來判斷瀏覽器的種類*/
圖層對象的4個屬性
document.getElementById(”ID”).innerText //動態(tài)輸出文本
document.getElementById(”ID”).innerHTML //動態(tài)輸出HTML
document.getElementById(”ID”).outerText //同innerText
document.getElementById(”ID”).outerHTML //同innerHTML
相關(guān)文章
在Javascript中 聲明時用"var"與不用"var"的區(qū)別
Javascript聲明變量的時候,雖然用var關(guān)鍵字聲明和不用關(guān)鍵字聲明,很多時候運行并沒有問題,但是這兩種方式還是有區(qū)別的2013-04-04
js nextSibling屬性和previousSibling屬性概述及使用注意
nextSibling屬性:該屬性表示當(dāng)前節(jié)點的下一個節(jié)點;如果其后沒有與其同級的節(jié)點,則返回null;previousSibling屬性:該屬性與nextSibling屬性的作用正好相反,接下來將詳細介紹下,感興趣的你不妨了解下哦,或許對你有所幫助2013-02-02
ASP.NET實現(xiàn)Repeater控件的數(shù)據(jù)綁定
這篇文章介紹了ASP.NET實現(xiàn)Repeater控件數(shù)據(jù)綁定的方法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-07-07
JavaScript獲取tr td 的三種方式全面總結(jié)(推薦)
這篇文章主要介紹了JavaScript獲取tr td 的三種方式,具體操作步驟大家可查看下文詳細講解,感興趣的小伙伴們可以參考一下。2017-08-08
Uglifyjs(JS代碼優(yōu)化工具)入門 安裝使用
Uglify JS 是一個服務(wù)端node.js的壓縮程序。需要的朋友可以測試下2012-03-03
三個js循環(huán)的關(guān)鍵字示例(for與while)
這篇文章主要介紹了三個js循環(huán)的關(guān)鍵字示例,主要是for與while,需要的朋友可以參考下2016-02-02
javascript處理表單示例(javascript提交表單)
這篇文章主要介紹了javascript處理表單示例,處理 各種表單, 以及鏈接,按鈕的通用組件,需要的朋友可以參考下2014-04-04

