Introduction to...LOGIN

Introduction to HTML DOM and new features

Introduction

  • In the core DOM, the properties and methods provided can already operate web pages. Why do we need HTMLDOM?

  • If in the core DOM, the node level in the web page is very deep, it will be very troublesome to access this node.

  • Then, HTMLDOM provides a method to directly find nodes by id, instead of starting from the HTML root node.


##New features of HTMLDOM

  • Each HTML tag corresponds to an element object. For example: <img> corresponds to an image object

  • . The attributes of each HTML tag correspond to the attributes of the corresponding element object in a one-to-one correspondence.

  • <!DOCTYPE HTML>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
            <title>php.cn</title>
            <script type="text/javascript">
            window.onload = function(){
                //获取网页中id=img01的图片对象
                var imgObj = document.getElementById("img1");
                //修改图片的属性的值,图片标记的属性,元素对象也能用。
                imgObj.src = "/upload/course/000/000/009/580af7f52278b486.jpg";
                imgObj.width = 400;
                imgObj.border = 2;
                imgObj.style = "cursor:pointer";
                imgObj.title = "唯美图片";
                //核心DOM中的属性方法,元素对象都能用
                imgObj.parentNode.bgColor = "#f0f0f0";
            }
            </script>
        </head>
        <body >
            <img id="img1" src="/upload/course/000/000/009/580ae23c4a88a881.jpg" />
        </body>
    </html>
    Next Section
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script type="text/javascript"> window.onload = function(){ //获取网页中id=img01的图片对象 var imgObj = document.getElementById("img1"); //修改图片的属性的值,图片标记的属性,元素对象也能用。 imgObj.src = "/upload/course/000/000/009/580af7f52278b486.jpg"; imgObj.width = 400; imgObj.border = 2; imgObj.style = "cursor:pointer"; imgObj.title = "唯美图片"; //核心DOM中的属性方法,元素对象都能用 imgObj.parentNode.bgColor = "#f0f0f0"; } </script> </head> <body > <img id="img1" src="/upload/course/000/000/009/580ae23c4a88a881.jpg" /> </body> </html>
submitReset Code
ChapterCourseware