<button id="test">点我</button> <script> var button={ clicked:false, click:function(){ debugger; this.clicked=true; console.assert(!(button.clicked),"The button has been clicked"); } } var elem=document.getElementById("test"); //error //elem.addEventListener("click",button.click,false); elem.addEventListener("click",bind(button,"click"),false); function bind(context,name){ return function(){ return context[name].apply(context,arguments); }; }
时间: 2024-12-20 16:12:39