zoukankan      html  css  js  c++  java
  • 关于this对象

    <!DOCTYPE html>
    <html>
    <head>
        <title>关于this对象</title>
        <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
        <script>
            function Person(username){
                var _self=this;
                this.username=username;
                /**
                 * setTimeout是window的方法,所以setTime内调用this,也就是调用window,这里开发者经常弄混
                 */
                setTimeout(function(){
                    _self.showName();
                },1000);
            }
            Person.prototype.showName=function(){
                alert(this.username);
            }
    
            var mm=new Person('mm');
    
    
            window.onload=function(){
                var oBtn=document.getElementsByTagName('input')[0];
                var myData=new Data();
                /**
                 * 此处不能直接 oBtn.onclick=myData.showData; 这样写会导入showData中this调用出错
                 * 国为onclick事件是按钮触发的所有this=HTMLInputElement
                 */
                oBtn.onclick=function(){
                    myData.showData();
                };
            }
    
            function Data(){
                this.idx=1024;
            }
            Data.prototype.showData=function(){
                alert(this.idx);
            }
        </script>
    </head>
    <body>
        <input type=button value=查询 />
    </body>
    </html>
  • 相关阅读:
    Django搭建环境
    python切片
    python数据类型
    jquery 淡入淡出属性
    Jquery Tab切换
    jQuery Clone方法
    jQuery属性操作
    python 变量以及循环
    获取网站目录
    posting-jsonobject-with-httpclient-from-web-api
  • 原文地址:https://www.cnblogs.com/BigIdiot/p/3080450.html
Copyright © 2011-2022 走看看