JavaScript事件属性event.target

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            #main {
                width: 200px;
                height: 100px;
                background: red;
            }
        </style>
        <script type="text/javascript">
            window.onload = function() {
                document.getElementById("main").onclick = function(e) {
                    console.log(e.target);
                    console.log(e.target.id);
                    console.log(e.target.tagName);
                    console.log(e.target.nodeName);
                    console.log(e.target.classList);
                    console.log(e.target.className);
                    console.log(e.target.innerHTML);
                    console.log(e.target.innerText);
                }
            }
        </script>
    </head>

    <body>
        <div id="main" class="sb js node"><span>我爱JavaScript</span></div>
    </body>

</html>


 

转: https://www.cnblogs.com/libin-1/p/5936997.html
 

JavaScript事件属性event.target

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <style type="text/css">
            #main {
                width: 200px;
                height: 100px;
                background: red;
            }
        </style>
        <script type="text/javascript">
            window.onload = function() {
                document.getElementById("main").onclick = function(e) {
                    console.log(e.target);
                    console.log(e.target.id);
                    console.log(e.target.tagName);
                    console.log(e.target.nodeName);
                    console.log(e.target.classList);
                    console.log(e.target.className);
                    console.log(e.target.innerHTML);
                    console.log(e.target.innerText);
                }
            }
        </script>
    </head>

    <body>
        <div id="main" class="sb js node"><span>我爱JavaScript</span></div>
    </body>

</html>


 

转: https://www.cnblogs.com/libin-1/p/5936997.html

相关文章:

  • 2022-01-29
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-16
  • 2022-01-25
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-26
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
相关资源
相似解决方案