事件后面一般对应的就是一个函数

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    7. <title>Document</title>
    8. <style>
    9. #app{
    10. width: 100px;
    11. height:100px;
    12. border: 1px solid black;
    13. }
    14. </style>
    15. </head>
    16. <body>
    17. <div id="app">
    18. </div>
    19. <script>
    20. var app = document.getElementById("app")
    21. /* 事件后面一般对应的就是一个函数 */
    22. app.onclick = function(){
    23. app.style.backgroundColor = "red"
    24. }
    25. </script>
    26. </body>
    27. </html>

    gif.gif 点击后 背景色变为红色