document

预备知识:childNodes:返回一个元素的子节点

document: 一个最顶层虚拟节点:他有两个子节点: <!DOCTYPE html>  

                                                                        <html lang="en">

      

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
    html{border: 1px solid red;}
    body{border: 1px solid #000;}
    .div1{width:100px;height:100px;background:green;}
    </style>
</head>
<body>
这是body
<div class="div1">
    
</div>
    <script>
    window.onload=function(){
        console.log("document.childNodes[0]"+":"+document.childNodes[0]);
        console.log("document.childNodes[0].tagName"+":"+document.childNodes[0].tagName);
        console.log("document.childNodes[1].tagName"+":"+document.childNodes[1].tagName);
document.body.onclick
=function(){ console.log("点击body"); } /*document.html.onclick=function(){ //没有document.html console.log(点击html); }*/ document.onclick=function(){ console.log("点击document"); } } </script> </body> </html>

以上可以看出 document html body 的范围

Document 对象

 每个载入浏览器的 HTML 文档都会成为 Document 对象。

 Document 对象使我们可以从脚本中对 HTML 页面中的所有元素进行访问。

 Document 对象是 Window 对象的一部分,可通过 window.document 属性对其进行访问

get...方法其他元素也可以用,继承?
 

转载于:https://www.cnblogs.com/everwangJS/p/4492218.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值