close

[JavaScript HTML DOM]使用document物件,使用屬性document.documentElement

說明:
document.documentElement 回傳此網頁文件中的根元素 (root element) ,
取得html的 HTML element的物件 。
此範例設計說明:
第一步、取得目前的document.documentElement
第二步、回傳的object HTMLHtmlElement,顯示到頁面上
程式:
<html>
<head>
<title>[JavaScript-HTML_DOM]使用document物件,使用屬性document.documentElement</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script>
function mytest() {
var rootElement = document.documentElement;
document.getElementById("returnData").innerHTML=rootElement
}
</script>
</head>
<body>
[JavaScript-HTML_DOM]使用document物件,使用屬性document.documentElement<br>
<input type="button" value="測試" onclick="mytest()" />
<span id="returnData"></span>
</body>
</html>
圖:


按下測試


相關範例:
待續





 






 















其它文章

arrow
arrow

    PG Levin Li 發表在 痞客邦 留言(0) 人氣()