美文网首页webAPI
webAPI_this关键字

webAPI_this关键字

作者: 椋椋夜色 | 来源:发表于2019-05-07 22:42 被阅读0次

    <!DOCTYPE html>
    <html lang="zh-CN">

    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title> webAPI_this关键字 </title>

    <style>
        .box {
            width: 200px;
            height: 200px;
            background-color: #f00;
        }
    </style>
    

    </head>

    <body>

    <input type="button" value="点我啊" id="btn">
    
    <div class="box"></div>
    
    <script>
        document.getElementById('btn').onclick = function () {
    
            console.log(this);
    
        }
    
        document.getElementsByClassName('box')[0].onclick = function () {
    
            console.log(this);
    
        };
    </script>
    

    </body>

    </html>

    相关文章

      网友评论

        本文标题:webAPI_this关键字

        本文链接:https://www.haomeiwen.com/subject/lovuoqtx.html