国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

js基礎之DOM中document對象的常用屬性方法詳解

2019-11-20 08:38:27
字體:
來源:轉載
供稿:網友

-----引入

每個載入瀏覽器的 HTML 文檔都會成為 Document 對象。

Document 對象使我們可以從腳本中對 HTML 頁面中的所有元素進行訪問。

屬性

1  document.anchors  返回對文檔中所有 Anchor 對象的引用。還有document.links/document.forms/document.images等

2  document.URL       返回當前文檔的url

3  document.title       返回當前文檔的標題

4  document.body    返回body元素節點

方法

1  document.close()     關閉用 document.open() 方法打開的輸出流,并顯示選定的數據。

<!DOCTYPE html><html><head><script>function createDoc(){var w=window.open();w.document.open();w.document.write("<h1>Hello World!</h1>");w.document.close();}</script></head><body><input type="button" value="New document in a new window" onclick="createDoc()"></body></html>

2  document.createElement()     創建元素節點。

<!DOCTYPE html><html lang="en"><!DOCTYPE html><head></head><body>  <p>hello world</p>  <script>  var a = document.createElement('hr');  document.body.appendChild(a)</script></body></html>

3  document.createAttribute()   創建屬性節點。

<!DOCTYPE html><html><body><p id="demo">Click the button to make a BUTTON element.</p><button onclick="myFunction()">Try it</button><script>function myFunction(){var btn=document.createElement("BUTTON");document.body.appendChild(btn);};</script></body></html>

4  document.createTextNode()  創建文本節點。

<!DOCTYPE html><html lang="en"><!DOCTYPE html><head></head><body>  <p>hello world</p><script>  var a = document.createTextNode('hahahah');  document.body.appendChild(a)</script></body></html>

5  document. getElementsByClassName()   返回文檔中所有指定類名的元素集合,作為 NodeList 對象集合。所謂NodeList對象集合,是一個類似于數組的數據格式,僅僅提供了length屬性,像數組中的push  pop方法等都未提供。

6  document.getElementById() 返回對擁有指定 id 的第一個對象的引用。

7  document.getElementsByName() 返回帶有指定名稱的對象集合。

8  document.getElementsByTagName() 返回帶有指定標簽名的對象集合。

9  document.write() 向文檔寫 HTML 表達式 或 JavaScript 代碼。注意:當html文檔加載完后再使用write方法,會導致write內容覆蓋掉原本的html文檔。

<!DOCTYPE html><html lang="en"><!DOCTYPE html><head></head><body>  <p>hello world</p><script>  document.write('hahahh')</script></body></html>

以上就是小編為大家帶來的js基礎之DOM中document對象的常用屬性方法詳解全部內容了,希望大家多多支持武林網~

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 聊城市| 景泰县| 霞浦县| 迁安市| 淮阳县| 开鲁县| 马关县| 秦皇岛市| 嘉善县| 井研县| 南涧| 灌南县| 厦门市| 龙井市| 开原市| 卓资县| 马关县| 阿鲁科尔沁旗| 建阳市| 吴忠市| 岳阳市| 忻州市| 阿克苏市| 澄城县| 泗洪县| 陆丰市| 台中市| 建德市| 汝阳县| 马山县| 旺苍县| 隆子县| 临夏县| 碌曲县| 景洪市| 灵丘县| 黄冈市| 高阳县| 灌云县| 辽中县| 临安市|