Dom簡介,武則天簡介

來源:互聯網
上載者:User

Dom簡介,武則天簡介


在網頁上,組成頁面(或文檔)的對象被組織在一個樹形結構中。

       頁面的頂級包含在<html>標籤中,在其中會找到<head>和<body>標籤,而其它標籤包含在這兩個標籤中,依次類推。
       javascript將文檔樹中的每一項都當做對象,可以使用javascript操縱這些對象。用來表示文檔中對象的標準模型就稱為DOM(Document Object Model)。


<html><head><title>Dom</title></head><body><form id="form1" action="#"><input type="button" id="b1" value="AddContent"></form><form id="form2" action="#"><input type="button" id="b2" value="AddContent"></form></body></html>

Document 對象集合


集   合 描    述
all[] 提供對文檔中所有 HTML 元素的訪問。
anchors[] 返回對文檔中所有 Anchor 對象的引用。
applets 返回對文檔中所有 Applet 對象的引用。
forms[] 返回對文檔中所有 Form 對象引用。
images[] 返回對文檔中所有 Image 對象引用。
links[] 返回對文檔中所有 Area 和 Link 對象引用。


    var doc = document.forms;     document.write(doc.length); 

        擷取頁面上所有的form表單的數組將表單數組的長度寫在頁面上,為2


Document 對象屬性


屬   性 描    述
body

提供對 <body> 元素的直接存取。

對於定義了框架組的文檔,該屬性引用最外層的 <frameset>。

cookie 設定或返回與當前文檔有關的所有 cookie。
domain 返回當前文檔的網域名稱。
lastModified 返迴文檔被最後修改的日期和時間。
referrer 返回載入當前文檔的文檔的 URL。
title 返回當前文檔的標題。
URL 返回當前文檔的 URL。


    var expireDate = new Date();    expireDate.setMonth(expireDate.getMonth()+6);        var userName = document.getElementById("nameField").value;    document.cookie = "userName=" + userName + ";expires=" + expireDate.toGMTString();
     設定瀏覽器cookie



Document 對象方法


方    法 描    述
close() 關閉用 document.open() 方法開啟的輸出資料流,並顯示選定的資料。
getElementById() 返回對擁有指定 id 的第一個對象的引用。
getElementsByName() 返回帶有指定名稱的對象集合。
getElementsByTagName() 返回帶有指定標籤名的對象集合。
open() 開啟一個流,以收集來自任何 document.write() 或 document.writeln() 方法的輸出。
write() 向文檔寫 HTML 運算式 或 JavaScript 代碼。
writeln() 等同於 write() 方法,不同的是在每個運算式之後寫一個分行符號。


    document.getElementById("days")
       取id為days的HTML對象

    備忘:上面幾個方法中,訪問頁面元素常用的有getElementById,getElementsByName 和 getElementsByTagName。

    其中 getElementById 返回的為單對象;getElementsByName為根據name擷取到的元素的集合,getElementsByTagName為根據tag名稱擷取到的元素的集合。

   

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.