TAILIEUCHUNG - Học JavaScript qua ví dụ part 70

W3C DOM và JavaScript Đi bộ với các DOM Trong ví dụ , chúng tôi sẽ phải mất một đi bộ trên cây DOM, một bước tại một thời điểm, sử dụng các cha / con / anh chị em các nút để đại diện cho từng yếu tố trong tài liệu. Cách bố trí đơn giản của trang HTML được vẽ trong hình 15,6 | 618 Chapter 15 The W3C DOM and JavaScript Walking with the DOM In Example we will take a walk down the DOM tree one step at a time using the parent child sibling nodes to represent each element in the document. The simple layout of the HTML page is drawn in Figure . You can quickly see that using DOM properties to navigate the tree can get confusing and if in any way the structure of the document changes then all the nodes properties will have to be reset. We discuss a quicker more efficient way to get around in the next section. Because every element in the tree has a parent other than the root node a relationship can be established going up or down the tree as long as you know which node and which children will lead you to the target element you want. The five properties for each node in the tree are parentNode firstChild lastChild previousSibling and next Sibling. document htmi root node head body title h1 The Nodes Walking with the Nodes Figure The DOM tree for Example . EXAMPLE 1 html head title The Nodes title style p font-size x-large color darkblue font-style bold style head body h1 Walking with Nodes h1 p Who knows what node p P From the Library of Walking with the DOM 619 EXAMPLE continued script type text javascript 2 var Parent 0 First child node is HTML 3 var Child 0 Parent s first child is HEAD The parent node is 4 br Get the name parent node The first child of the parent node is 5 br The node below the child is 6 0 .nodeName br The text node below title is 7 0 .childNodes 0 .nodeName br The value of the text node is 8 0 .childNodes 0 .nodeValue br The first child of the parent is 9 br .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.