2017-01-23 49 views
-1

我有以下jQuery的滑块打开子菜单,当父项被点击。它在Chrome上工作正常,但在Firefox上的子菜单不打开。有任何想法吗 ?jQuery子菜单不在Firefox中打开

(function($) { 
"use strict"; 

    $('.menu-area ul li').on('click', function() { 

if($(this).closest("li").children("ul").length) { 
    event.preventDefault(); 
    $(this).children('ul').slideToggle(300); 
} 
else{ 
    event.preventDefault(); 
    $('.screen-washer').removeClass("right"); 
    //$('.screen-washer').addClass("left"); 

    //console.log($('a').attr('href')); 
    var linkLocation = $(this).children('a:first').attr('href'); 
     //alert(linkLocation); 
     if (linkLocation.indexOf('#') >= 0) {} else { 
      setTimeout(function() { 
       //$('.preloader').fadeIn(300); 
       window.location = linkLocation; 
      }, 500); 
     } 

} 
    }); 

})(jQuery); 
+1

@Scott嗨,你能不能也分享你的HTML? –

回答

1

在事件处理 - ()的函数 - “事件”的缺失,所以Mozilla的一个错误停止当它达到在分析非可变量。

应该是:

$('.menu-area ul li').on('click', function(event) {...} 
+0

更具体地说,只使用'function()'是完全合法的,但是你在函数中引用'event'('event。preventDefault()'),所以你需要包含它。 –

+0

是的,Mozilla在遇到preventDefault时写入了ReferenceError,而Chrome没有说什么。 –

+0

是的,Chrome“帮助”为你预先定义变量_event_。如果它被称为别的东西,说'ev'或'e',它也会在Chrome中失败。 –