JavaScript-------------Dom操作(一)

JavaScript-------------Dom操作(一)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<!--背景顏色爲白色,字體顏色爲綠色,鏈接顏色爲紅色,未被瀏覽過的連接顏色爲#ffff00-->
<body bgcolor="white" text="green" link="red" alink="#ffff00">

<h1 align="center">Test Document</h1>
<hr>
<!-- 該標籤同時具有href、Area(文本)-->
<a href="#">Sample link</a>
<!-- 該標籤同時都沒有href、Area(文本)-->
<a name="anchor1"></a>
<a name="anchor2" href="#a">Sample link2</a>
<form name="form1"></form>
<form name="form2"></form>
<hr>
<script>
    window.document.write("<h1 align='center'> Document Object Properties</h1><br>");
    window.document.write("<h2>Basic Page Properties</h2>");
    window.document.write("Location = "+window.document.location+"<br>");
    window.document.write("URL = " + window.document.URL + "<br>");
    window.document.write("Document Title = " + window.document.title + "<br>");
    window.document.write("Document Last Modification Date = " + window.document.lastModified+"<br>");
    window.document.write("<h2>Page Color</h2>");
    window.document.write("Background Color = " + window.document.bgColor + "<br>");
    window.document.write("Text Color = " + window.document.fgColor + "<br>");
    window.document.write("Link Color = "+window.document.linkColor + "<br>");
    window.document.write("ActiveLink Color = "+window.document.alinkColor + "<br>");
    window.document.write("Visited Link Color = "+window.document.vlinkColor + "<br>");
    if (window.document.links.length > 0){
        window.document.write("<h2>Links</h2>");
        window.document.write("# Links = "+window.document.links.length + "<br>");
        for(var i=0;i<window.document.links.length;i++){
            window.document.write("Links[" + i + "]=" +window.document.links[i] + "<br>");
        }
    }
    /*只輸出那些同時具有href和area值的標籤*/
    window.document.write(""+window.document.links.length);

    if(window.document.anchors.length > 0){
        window.document.write("<h2>Anchors</h2>");
        window.document.write("# Anchors = " + window.document.anchors.length + "<br>");
        for(var i =0;i<window.document.anchors.length;i++){
            window.document.write("Anchors[" + i +"]=" + window.document.anchors[i] + "<br>");
        }
    }
    if(window.document.forms.length > 0){
        window.document.write("<h2>Forms></h2>");
        window.document.write("# Forms = " + window.document.forms.length + "<br>");
        for(var i = 0; i <window.document.forms.length;i++){
            window.document.write("Form[ " + i + "] = "+window.document.forms[i].name + "<br>");
        }
    }
</script>
</body>
</html>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章