我发现js中的removeEventListener或者detachEvent只对attach上去的事件有用jquery的unbind好像也只对bind上去的事件有效果如果是直接写在html标签里的的事件不能解除,这个怎么办?

解决方案 »

  1.   

    比如你对一个div写了onclick=function....
    那么就 document.getElementById('div的id').onclick=null;
      

  2.   

    onclick=null在ff下不行,ie6下是可以的
      

  3.   


      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
     <head>
      <title> new document </title>
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
     </head> <body>
       <div id="test">Click Me!</div>
       
       <script type="text/javascript">
       //<![CDATA[
         document.getElementById('test').onclick=function(){
        alert(this.innerHTML);
     };
     
      document.getElementById('test').onclick=undefined || null;
       //]]>
       </script>
     </body>
    </html>