zoukankan      html  css  js  c++  java
  • JS this关键字

     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="UTF-8">
     5         <title></title>
     6         <style type="text/css">
     7             #box{
     8                 width: 200px;
     9                 height: 500px;
    10                 background: gray;
    11             }
    12             .child{
    13                 width: 100%;
    14                 height: 100px;
    15                 background: red;
    16                 border: 1px solid black;
    17             }
    18         </style>
    19     </head>
    20     <body>
    21         <div id="box">
    22             <div class="child"></div>
    23             <div class="child"></div>
    24             <div class="child"></div>
    25         </div>
    26     </body>
    27         
    28         <script type="text/javascript">
    29             var box = document.getElementById("box");
    30             box.onclick = function(){
    31                 this.style.background= "green";
    32             }
    33         
    34 
    35 
    36         
    37         function fun1{
    38 
    39         }console.log(this);// this 代指 window
    40         
    41 
    42 
    43 
    44     //   补充知识点:
    45     var value = document.getElementsByTagName("div");
    46     var  fatherBox = document.getElementById("box");
    47     // 获取 box 下面所有的 div 块
    48     var childs = fatherBox.getElementsByTagName("div");
    49         
    50         </script>
    51         
    52 </html>
  • 相关阅读:
    文件操作
    set集合,深浅拷贝
    is 和 == 区别 id()函数
    字典
    列表
    基本数据类型
    第十二章 if测试和语法规则
    第十一章 赋值、表达式和打印
    第十章 python语句简介
    第九章元组、文件及其他
  • 原文地址:https://www.cnblogs.com/PowellZhao/p/5542396.html
Copyright © 2011-2022 走看看