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

js基礎(chǔ)之DOM中document對(duì)象的常用屬性方法詳解

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

-----引入

每個(gè)載入瀏覽器的 HTML 文檔都會(huì)成為 Document 對(duì)象。

Document 對(duì)象使我們可以從腳本中對(duì) HTML 頁(yè)面中的所有元素進(jìn)行訪問。

屬性

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

2  document.URL       返回當(dāng)前文檔的url

3  document.title       返回當(dāng)前文檔的標(biāo)題

4  document.body    返回body元素節(jié)點(diǎn)

方法

1  document.close()     關(guān)閉用 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é)點(diǎn)。

<!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é)點(diǎn)。

<!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é)點(diǎn)。

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

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

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

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

9  document.write() 向文檔寫 HTML 表達(dá)式 或 JavaScript 代碼。注意:當(dāng)html文檔加載完后再使用write方法,會(huì)導(dǎo)致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基礎(chǔ)之DOM中document對(duì)象的常用屬性方法詳解全部?jī)?nèi)容了,希望大家多多支持腳本之家~

相關(guān)文章

最新評(píng)論

织金县| 保定市| 嘉黎县| 南丹县| 界首市| 三门县| 南阳市| 怀集县| 西平县| 泽库县| 收藏| 明星| 河北省| 囊谦县| 深水埗区| 龙陵县| 周至县| 勐海县| 吴桥县| 凤翔县| 克什克腾旗| 河源市| 蓝田县| 阿坝县| 恩施市| 凤庆县| 汪清县| 九龙县| 城步| 田东县| 临海市| 北碚区| 孟连| 安塞县| 社旗县| 花莲市| 望江县| 民丰县| 岢岚县| 浮梁县| 台山市|