zoukankan      html  css  js  c++  java
  • js this

    <script type="text/javascript">
         function to_green(){
            this.style.color="green";
        }
        function init_page(){
        var example=document.getElementById("example");
            example.onclick=to_green;
       }
       window.onload=init_page;
    </script>
    <a href="#" id="example" style="color: red;">点击变绿</a>

    定义:this是包含它的函数作为方法被调用时所属的对象,
     1、包含它的函数。2、作为方法被调用时。3、所属的对象。
    function to_green(){
    this.style.color="green";
    }
    to_green();
    函数所属的对象 默认情况是window 并没有style这个属性
    通过赋值操作,example对象的onclick得到to_green的方法,那么包含this的函数就是to_green()喽,
    onclick事件是让example对象调用了to_green()函数,所以this指向example



    <!DOCTYPE html>
    <html>
    <body>
    <p>点击下面的按钮,循环遍历对象 "person" 的属性。</p>
    <button onclick="myFunction()">点击这里</button>
    <p id="demo"></p>
    
    <script>
    function myFunction()
    {
    var x;
    var txt="";
    var person={fname:"Bill",lname:"Gates",age:56}; 
    
    for (x in person)
    {
    txt=txt + person[x];
    }
    
    document.getElementById("demo").innerHTML=txt;
    }
    </script>
    </body>
    </html>
    

     for  in 循环

  • 相关阅读:
    struts2 标签给iterator添加自然序号
    theirtts2
    zhihutheirTTS1
    theirs《A 2019 Guide to Speech Synthesis with Deep Learning》
    theirmvsnetv00000
    theirmvsnetv2
    theirMeshCNN/
    their MVF-Net: Multi-View 3D Face Morphable Model Regression(2019 CVPR)
    their DenseFusion6dof
    C++35
  • 原文地址:https://www.cnblogs.com/zuichumx0826/p/9063658.html
Copyright © 2011-2022 走看看