代码
提交代码
<style> .btn { border: 1px solid #4caf50; padding: 8px 12px; min-width: 200px; color: #4caf50; background: white; outline: none; } .btn:active { background: #4caf50; color: white; } </style> <div> <button class="btn">点击我</button> </div> <script> var afterClick = new Event('afterclick'); var btnEle = document.querySelector('.btn'); btnEle.addEventListener('afterclick', function() { alert('我是点击事件执行完后做的事情'); }); btnEle.onclick = function() { alert('我被点击了'); this.dispatchEvent(afterClick); }; </script>
运行结果