<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script> window.onload = function () { // 移除事件的兼容性处理 function removeEventListener(ele, eventType, fn) { // 判断当前浏览器是否支持removeEventListener方法 if (ele.removeEventListener) { ele.removeEventListener(eventType, fn); } else if (ele.detachEvent) { ele.detachEvent('on' + eventType, fn); } else { ele['on' + eventType] = null; } } var btn = document.getElementById('btn'); function fn() { alert('你好'); removeEventListener(btn, 'click', fn); } btn.addEventListener('click', fn); } </script> </head> <body> <input type="button" value="点击" id="btn"> </body> </html>