詳解HTML中的window對象和document對象,windowdocument

來源:互聯網
上載者:User

詳解HTML中的window對象和document對象,windowdocument

Window -- 代表瀏覽器中一個開啟的視窗:

對象屬性
  window //視窗自身
  window.self //引用本窗戶window=window.self
  window.name //為視窗命名
  window.defaultStatus //設定窗戶狀態列資訊
  window.location //URL地址,配備布置這個屬性可以開啟新的頁面

對象方法
  window.alert("text") //提示資訊會話框
  window.confirm("text") //確認會話框
  window.prompt("text") //要求鍵盤輸入會話框
  window.setIntervel("action",time) //每一隔指定的時間(毫秒)就執行一次操作
  window.clearInterval() //清除時間配備布置作用就是終止輪迴
  window.setTimeout(action,time) //隔了指定的時間(毫秒)執行一次操作
  window.open() //開啟新的視窗
  window.close() //關閉視窗

成員對象
  window.event
  window.document //見document對象詳解
  window.history
  window.screen
  window.navigator
  window.external
  -------------------------------------------------- -------------------
  window.history對象
  window.history.length //瀏覽過的頁面數
  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 //可用高度(除去工作列的高度)
  -------------------------------------------------- -------------------
  window.external對象
  window.external.AddFavorite("地址","標題" ) //把網站新增到保藏夾
  -------------------------------------------------- -------------------
  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對象 -- 代表整個HTML 文檔,可用來訪問頁面中的所有元素:

對象屬性

document.title                 //設定文檔標題等價於HTML的<title>標籤
document.bgColor               //設定頁面背景色
document.fgColor               //設定前景色彩(文本顏色)
document.linkColor             //未點擊過的連結顏色
document.alinkColor            //啟用連結(焦點在此連結上)的顏色
document.vlinkColor            //已點擊過的連結顏色
document.URL                   //設定URL屬性從而在同一視窗開啟另一網頁
document.fileCreatedDate       //檔案建立日期,唯讀屬性
document.fileModifiedDate      //檔案修改日期,唯讀屬性
document.fileSize              //檔案大小,唯讀屬性
document.cookie                //設定和讀出cookie
document.charset               //設定字元集 簡體中文:gb2312

常用對象方法
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          // 網域名稱+連接埠號碼
document.location.hostname      // 網域名稱
document.location.href          // 完整URL
document.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
========================================================================
images集合(頁面中的圖象):
----------------------------
a)通過集合引用
document.images                 //對應頁面上的<img>標籤
document.images.length          //對應頁面上<img>標籤的個數
document.images[0]              //第1個<img>標籤          
document.images[i]              //第i-1個<img>標籤
----------------------------
b)通過nane屬性直接引用
<img name="oImage">
document.images.oImage          //document.images.name屬性
----------------------------
c)引用圖片的src屬性
document.images.oImage.src      //document.images.name屬性.src

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.