2014-09-24 66 views
2

請幫助下面的代碼。錯誤:ReferenceError:未定義事件

我得到「事件未定義」的錯誤在Firefox和ie。

該問題似乎與event.preventDefault();

這個CSS只是關閉下拉菜單

<style type="text/css"> 
    .dropdown { 
     display: none; 
     opacity: 0; 
    } 
    </style> 

jQuery的

自定義JavaScript

<script type="text/javascript"> 

       $(document).ready(function(){ 

        jQuery('.download-dropdown > a').click(function() { 
         event.preventDefault(); 
         var $this=jQuery(this); 
         if (!$this.parent().hasClass('active')) { 
          var top=$this.parent().offset().top; 
          var left=$this.parent().offset().left; 
          jQuery('body').append($this.parent()); 
          $this.parent().addClass('active'); 
          $this.parent().css({ 'position': 'absolute', 
               'top': top, 
               'left': left, 
               'z-index': 999}); 
          $this.parent().children('.dropdown').animate({ 'opacity': '1','height': 'toggle'}); 
          $this.parent().animate({'height': '400'}); 
          window.dropdown=$this; 
         } 
         else { 
          $this.parent().css({ 'position': 'relative', 
               'top': 'inherit', 
               'left': 'inherit', 
               'z-index': 1}); 
          $this.parent().removeClass('active'); 
          jQuery('article.contact-download > div > section > div').append($this.parent()); 
          $this.parent().children('.dropdown').animate({ 'opacity': '0','height': 'toggle'}); 
          $this.parent().animate({'height': '45'}); 
         } 

        }); 



       }); 

      </script> 

這是HTML

<article class="contact-download" data-background-height="60"> 
     <section data-speed="0"> 
     <div> 
      <div class="download-dropdown" style="height: 60px; position: relative; z-index: 1; top: inherit; left: inherit; display: inline-table"> <a style="padding-left: 25px; text-decoration:none; " href="#">click to see more</a> 
      <div class="dropdown"> 
       <ul> 
       <li><a href="#">Link 1</a></li> 
       <li><a href="#">Link 2</a></li> 
       <li><a href="#">Link 3</a></li> 
       <li><a href="#">Link 4</a></li> 
       </ul> 
      </div> 
      </div> 
     </div> 
     </section> 
    </article> 

回答

1

您需要設置爲功能參數:

jQuery('.download-dropdown > a').click(function(event) { 
    // event is defined now      __^__ 
相關問題