JS注册事件

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        //要操作页面的元素(标签)那就要写到onload中,

    //不操作可以不用     


        function f1() {
            alert('迁徙猿有很多猿');
        }


        onload = function () {


        //在html中注册事件加(),在这写不加
            document.getElementById('btn').onclick = f1; 注册事件
        };
    </script>
</head>
<body>
    <input type="button" name="name" value="神奇的按钮" id="btn" />
    <!-- onclick="f1();"-->执行代码
</body>
</html>
原文地址:https://www.cnblogs.com/dxmfans/p/9434871.html