【问题标题】:Jquery .fadeToggle() works on one page, doesn't on another (same code)Jquery .fadeToggle() 在一个页面上工作,在另一个页面上不起作用(相同的代码)
【发布时间】:2013-02-03 11:22:00
【问题描述】:

使用 Jquery (1.7.1) 我正在尝试在 .hover() 上制作图像 .fadeToggle

图片在页面顶部,上面写着“Concurso de Desfraces....”

代码在此页面上有效:https://tienda.lirainwonderland.es

为什么在这个页面上不起作用?http://lirainwonderland.es

我可以在 .hover() 上发出警报,所以我确定问题出在 .fadeToggle()

我已尝试使用 firebug 来查找此问题的根源,当我在线中断脚本时,脚本面板的堆栈选项卡上似乎确实存在差异,但不知道为什么...

这里是javascript:

$(document).ready(function () {
 $("#concurso").hover(function () { 
   $('#concurso2').fadeToggle("slow", "linear");            
});
});

这是 CSS:

#concurso {
 position: relative;
}

#concurso2 {
    display: none;
    position: absolute;
    top: -240px;
    left: 0;
}

这里是 HTML:

<a id="concurso" href="">
  <img id="concurso1" src="/images/consurso_de_disfraces_carnival_2013_rojo_inico.png" alt="Concurso de Disfraces Lira in Wonderland 2013" />
  <img id="concurso2" src="/images/consurso_de_disfraces_carnival_2013_rosa_inico.png" alt="Concurso de Disfraces Lira in Wonderland 2013" />
</a>

【问题讨论】:

    标签: javascript jquery wordpress firebug


    【解决方案1】:

    当你刚刚运行代码时,你会看到一个错误

    $('#concurso2').fadeToggle("slow", "linear");
    

    尝试在 http://lirainwonderland.es/ 上运行它

    这意味着您的 2 个页面上有不同的版本

    jQuery.fn.jquery; // checks jQuery version
    

    但那不是问题,您的 $() 似乎不是 jQuery,也许您那里还有其他脚本,例如 mootools、原型等

    你可以用 jQuery 代替 $,我试过了。

    jQuery('#concurso2').fadeToggle("slow", "linear");
    

    【讨论】:

    • 这是我在 lirainwonderland.es 上运行的代码,似乎不起作用。我只是从 tienda.lirainwonderland.es 复制并粘贴了有效的代码。
    • 在控制台日志中,你使用的是chrome还是firefox?
    • 看起来 jQuery 在 lirainwonderland.es 上包含了两次(1.7.1 和 1.7.2)
    • 使用 jQuery(selector) 对我有用,尽管在调整代码之前检查后我没有看到 consol 日志中弹出任何错误。这个网站上的代码有点乱,我将不得不改天清理它。非常感谢 fedmich!
    • 酷。您可能想阅读有关缩小 javascripts 的信息,所有这些脚本也可以合并到 1 个 js 文件中。但那是另一个故事,另一天:)
    猜你喜欢
    • 2015-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多