ReferenceError:事件在Firefox中没有定义错误
我为一个客户做了一个页面,最初我在Chrome中工作,忘记检查它是否在Firefox中工作。 现在,我遇到了一个很大的问题,因为整个页面都是基于一个在Firefox中不起作用的脚本。
它基于所有的“链接”,有一个rel导致隐藏和显示正确的页面。 我不明白为什么这不是在Firefox中工作。 
 例如,页面的ID为#menuPage , #aboutPage等。 所有链接都有这样的代码: 
 <a class="menuOption" rel='#homePage' href="#">Velkommen</a> 
它在Chrome和Safari中完美运行。
这里是代码:
 $(document).ready(function(){ //Main Navigation $('.menuOption').click(function(){ event.preventDefault(); var categories = $(this).attr('rel'); $('.pages').hide(); $(categories).fadeIn(); }); // HIDES and showes the right starting menu $('.all').hide(); $('.pizza').show(); // Hides and shows using rel tags in the buttons $('.menyCat').click(function(event){ event.preventDefault(); var categori = $(this).attr('rel'); $('.all').hide(); $(categori).fadeIn(); $('html,body').scrollTo(0, categori); }); }); 
	
你正在声明(一些)你的事件处理程序不正确:
 $('.menuOption').click(function( event ){ // <---- "event" parameter here event.preventDefault(); var categories = $(this).attr('rel'); $('.pages').hide(); $(categories).fadeIn(); }); 
您需要“事件”作为处理程序的参数。 WebKit遵循IE的“事件”使用全局符号的旧行为,但Firefox不。 当你使用jQuery时,这个库规范了行为,并确保事件处理程序传递了事件参数。
  编辑 – 澄清:你必须提供一些参数名称; 使用event清楚你的意图,但你可以称之为e或cupcake或其他任何东西。 
还要注意,你可能应该使用从jQuery传入的参数而不是“本机”(在Chrome,IE和Safari中)的原因是,这个参数是一个jQuery包装本地事件对象。 包装是规范化跨浏览器的事件行为。 如果你使用全球版本,你不明白。
 这是因为你忘记把event传入clickfunction: 
 $('.menuOption').on('click', function (e) { // <-- the "e" for event e.preventDefault(); // now it'll work var categories = $(this).attr('rel'); $('.pages').hide(); $(categories).fadeIn(); }); 
 在附注中, e更常用于单词event因为在大多数浏览器中, Event是全局variables。 
- jQuery的event.preventDefault()不工作在Firefox(包括JSFiddle)
- 在Firefox中访问文件下载对话框
- Firefox webdriver始终打开第一个运行页面
- FireFox是如何工作的? 源代码遍历?
- Firefox中的jQuery html()使用.innerHTML忽略DOM更改
- Webdriver无法在45000 ms后连接到端口7055上的主机127.0.0.1
- Firefox 5'caching'301redirect
- Firefox和Chrome在本地主机上运行缓慢; 已知的修复程序在Windows 7上不起作用
- 如何阻止Selenium使用Web驱动程序创build临时的Firefoxconfiguration文件?