用原生js给一个按钮绑定两个onclick事件

时间:2020-05-01
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">
        * {
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
<button id="btn">点击</button>
<script>
    document.getElementById('btn').addEventListener('click',function () {
        alert('1');
    });
    document.getElementById('btn').addEventListener('click',function () {
        alert('2');
    });
</script>
</body>
</html>

EventTarget.addEventListener()

target.addEventListener(type, listener, options);
target.addEventListener(type, listener, useCapture);