Jquery代码在Chrome中运行但在Firefox中不运行

我有这段代码,当它被点击时会显示几个div,然后一旦点击另一个链接就隐藏它们。 我试图在Firefox中显示这个并且它可能不是js中的问题但是非常感谢所有帮助。

 $(document).ready(function(){ $('.fadein').click(function(){ // Make the id overview show $('#header-contact').hide('slow'); $('#header-portfolio').show('slow'); $('#content-portfolio').show('slow'); // override default a behavior return false; }); });   $(document).ready(function(){ $('.fadein2').click(function(){ // Make the id overview show $('#header-portfolio').hide('slow'); $('#header-contact').show('slow'); $('#content-portfolio').hide('slow'); // override default a behavior return false; }); });   $(document).ready(function(){ $('.fadein3').click(function(){ // Make the id overview show $('#header-portfolio').hide('slow'); $('#header-contact').hide('slow'); $('#content-portfolio').hide('slow'); // override default a behavior return false; }); }); 

尝试将event传递给每个click处理程序,在return false之前,在传入的event对象上调用preventDefault()

例:

 $(document).ready(function(){ $('.fadeinX').click(function(e){ // Make the id overview show $('#header-portfolio').hide('slow'); $('#header-contact').hide('slow'); $('#content-portfolio').hide('slow'); // override default a behavior e.preventDefault(); return false; }); }); 

使用Chris Pederic的Web Developer清除缓存。 我与Firefox有完全相同的问题,并使用Web开发人员清除缓存解决了它。 简单,但你永远不知道,我一直在拉我的头发。

如果你使用preventDefault();你实际上根本不需要return false preventDefault();

  $(document).ready(function(){ $('.fadein').click(function(e){ // Make the id overview show $('#header-portfolio').hide('slow'); $('#header-contact').hide('slow'); $('#content-portfolio').hide('slow'); // override default a behavior e.preventDefault(); }); }); 

同时将你的JS移动到它自己的文件中,只有一个$(document).ready(function() {...})函数,你可以将所有三个事件放在那里。