事件的添加

74 阅读1分钟
```<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <!-- 内联添加 -->
    <!-- 内联添加很少使用
    要三点(结构、样式、脚本)分离 ,方便维护-->
    <button onclick="show()">点击</button>
    <script>
        // 脚本添加
        var bt1=document.getElementsByTagName("button")[0];
        bt1.onclick=function(){
            console.log("hello");
        }

        function show(){
            console.log("hello");
        }
    </script>
</body>
</html>