zoukankan      html  css  js  c++  java
  • this的应用

     1 <!DOCTYPE HTML>
     2 <html>
     3 <head>
     4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     5 <title>无标题文档</title>
     6 
     7 <script>
     8 
     9 /*
    10 alert(this);            window
    11 
    12 fn1(this);
    13 function fn1(obj){
    14     obj => window
    15 }
    16 
    17 oDiv.onclick = function (){
    18     this
    19     fn1(this);
    20 };
    21 function fn1(obj){  obj => oDiv }
    22 */
    23 
    24 window.onload = function (){
    25     var aBtn = document.getElementsByTagName('input');
    26     var that = null;            //
    27     
    28     for(var i=0; i<aBtn.length; i++){
    29         /*
    30         aBtn[i].onclick = function (){
    31             // this.style.background = 'yellow';
    32             
    33             that = this;
    34             
    35             fn1();
    36         };
    37         */
    38         aBtn[i].onclick = fn1;
    39     }
    40     
    41     function fn1(){
    42         // this        =>  window
    43         // that.style.background = 'yellow';
    44         
    45         // this.style.background = 'red';
    46     }
    47 };
    48 </script>
    49 
    50 </head>
    51 
    52 <body>
    53 
    54 <input type="button" value="按钮1" />
    55 <input type="button" value="按钮2" />
    56 <input type="button" value="按钮3" />
    57 
    58 </body>
    59 </html>
  • 相关阅读:
    低功耗蓝牙(BLE)——概念
    低功耗蓝牙(BLE)——概述
    190923——我目前的居所
    190922——真随笔
    行业——5G
    190901——无题
    190831——关于坚持
    190828-对话体
    190827——两种人
    190826-快乐
  • 原文地址:https://www.cnblogs.com/hduhdc/p/5258498.html
Copyright © 2011-2022 走看看