JS的Document屬性和方法document.title //設定文檔標題等價於HTML的title標籤document.bgColor //設定頁面背景色document.fgColor //設定前景色彩(文本顏色)document.linkColor //未點擊過的連結顏色document.alinkColor //啟用連結(焦點在此連結上)的顏色document.vlinkColor //已點擊過的連結顏色document.URL //設定URL屬性從而在同一視窗開啟另一網頁document.fileCreatedDate //檔案建立日期,唯讀屬性document.fileModifiedDate //檔案修改日期,唯讀屬性document.charset //設定字元集 簡體中文:gb2312document.fileSize //檔案大小,唯讀屬性document.cookie //設定和讀出cookie———————————————————————常用對象方法document.write() //動態向頁面寫入內容document.createElement(Tag) //建立一個html標籤對象document.getElementById(ID) //獲得指定ID值的對象document.getElementsByName(Name) //獲得指定Name值的對象document.body.appendChild(oTag)———————————————————————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) //動態產生一個HTML對象常用對象事件document.body.onclick=”func()” //滑鼠指標單擊對象是觸發document.body.onmouseover=”func()” //滑鼠指標移到對象時觸發document.body.onmouseout=”func()” //滑鼠指標移出對象時觸發———————————————————————location-位置子物件document.location.hash // #號後的部分document.location.host // 網域名稱+連接埠號碼//好像返回的是主機名稱localhost,沒有返回連接埠號碼document.location.hostname // 網域名稱document.location.href // 完整URLdocument.location.pathname // 目錄部分document.location.port // 連接埠號碼document.location.protocol // 網路通訊協定(http:)document.location.search // ?號後的部分documeny.location.reload() //重新整理網頁document.location.reload(URL) //開啟新的網頁document.location.assign(URL) //開啟新的網頁document.location.replace(URL) //開啟新的網頁———————————————————————selection-選區子物件document.selection例如:<div>請選中這裡的部分文字。</div><div><input type="button" value="請選中部分文字,然後點擊這裡執行 empty" onclick="javascript:Foo();" /></div><script type="text/javascript" language="javascript"><!--function Foo(){ document.selection.empty();}--></script> selection的createRange方法document.selection.createRange() 根據當前文字選擇返回 TextRange 對象,或根據控制項選擇返回 ControlRange 對象。配合 execCommand,在 HTML 編輯程式中很有用,比如:文字加粗、斜體、複製、粘貼、建立超連結等。這些好像都是只有在IE下才能實現。。———————————————————————images集合(頁面中的圖象)a)通過集合引用document.images //對應頁面上的img標籤document.images.length //對應頁面上img標籤的個數document.images[0] //第1個img標籤document.images[i] //第i-1個img標籤b)通過name屬性直接引用img name=”oImage”document.images.oImage //document.images.name屬性c)引用圖片的src屬性document.images.oImage.src //document.images.name屬性.srcd)建立一個圖象var oImageoImage = new Image()document.images.oImage.src=”1.jpg”同時在頁面上建立一個img /標籤與之對應就可以顯示———————————————————————-forms集合(頁面中的表單)a)通過集合引用document.forms //對應頁面上的form標籤document.forms.length //對應頁面上/formform標籤的個數document.forms[0] //第1個/formform標籤document.forms[i] //第i-1個/formform標籤document.forms[i].length //第i-1個/formform中的控制項數document.forms[i].elements[j] //第i-1個/formform中第j-1個控制項b)通過標籤name屬性直接引用/formform name=”Myform”>input name=”myctrl”/>/formdocument.Myform.myctrl //document.表單名.控制項名c)訪問表單的屬性document.forms[i].name //對應form name>屬性document.forms[i].action //對應/formform action>屬性document.forms[i].encoding //對應/formform enctype>屬性document.forms[i].target //對應/formform target>屬性document.forms[i].appendChild(oTag) //動態插入一個控制項document.all.oDiv //引用圖層oDivdocument.all.oDiv.style.display=”" //圖層設定為可視document.all.oDiv.style.display=”none” //圖層設定為隱藏document.getElementId(”oDiv”) //通過getElementId引用對象document.getElementId(”oDiv”).style=”"document.getElementId(”oDiv”).display=”none”/*document.all表示document中所有對象的集合只有ie支援此屬性,因此也用來判斷瀏覽器的種類*/ 圖層對象的4個屬性document.getElementById(”ID”).innerText //動態輸出文本document.getElementById(”ID”).innerHTML //動態輸出HTMLdocument.getElementById(”ID”).outerText //同innerTextdocument.getElementById(”ID”).outerHTML //同innerHTML /* PCAS (Province City Area Selector 省、市、地區聯動選擇JS封裝類) Ver 2.01 資料壓縮完整版 *\ 製作時間:2005-12-30 更新時間:2006-01-24 資料修正:2006-08-17 文檔大小:18KB 示範地址:http://www.popub.net/script/PCAS.html :http://www.popub.net/script/PCASClass.js 應用說明:頁麵包含<script type="text/javascript" src="PCASClass.js"></script>省市聯動new PCAS("Province","City")new PCAS("Province","City","吉林省")new PCAS("Province","City","吉林省","吉林市")省市地區聯動new PCAS("Province","City","Area")new PCAS("Province","City","Area","吉林省")new PCAS("Province","City","Area","吉林省","松原市")new PCAS("Province","City","Area","吉林省","松原市","寧江區")省、市、地區對象取得的值均為實際值。註:省、市、地區提示資訊選項的值為""(Null 字元串)