最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2016年10月28日 10:06:08   投稿:jingxian  
下面小編就為大家?guī)硪黄猨s基礎之DOM中document對象的常用屬性方法詳解。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

-----引入

每個載入瀏覽器的 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元素節(jié)點

方法

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

<!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()     創(chuàng)建元素節(jié)點。

<!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()   創(chuàng)建屬性節(jié)點。

<!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()  創(chuàng)建文本節(jié)點。

<!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對象集合,是一個類似于數(shù)組的數(shù)據(jù)格式,僅僅提供了length屬性,像數(shù)組中的push  pop方法等都未提供。

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

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

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

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

<!DOCTYPE html>
<html lang="en">
<!DOCTYPE html>
<head>
</head>
<body>
  <p>hello world</p>

<script>
  document.write('hahahh')


</script>
</body>
</html>

以上就是小編為大家?guī)淼膉s基礎之DOM中document對象的常用屬性方法詳解全部內(nèi)容了,希望大家多多支持腳本之家~

相關文章

最新評論

绥棱县| 阜新| 芦山县| 榕江县| 克拉玛依市| 民权县| 盐源县| 庐江县| 宜川县| 民县| 皮山县| 洛宁县| 荣成市| 汪清县| 涟源市| 昭苏县| 泾源县| 泰顺县| 陆河县| 蕲春县| 临澧县| 上栗县| 固始县| 南靖县| 嘉兴市| 巨鹿县| 乾安县| 彰化市| 广南县| 商丘市| 安阳市| 视频| 贵阳市| 锦州市| 马公市| 桐柏县| 甘南县| 道真| 郑州市| 西宁市| 隆尧县|