jquery悬停函数onLoad在firefox中不起作用

jquery hover function onLoad not working in firefox

本文关键字:firefox 不起作用 onLoad 悬停 函数 jquery      更新时间:2023-09-26

此代码在Chrome和IE中工作,但在Firefox中不起作用!

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

JS:

   $(window).load(function(){
    $("#bostitchTitle_Printable_1, #bostitchTitle_Printable_2").hover(function () {
        $(this).toggleClass("hoverblueL");
      });
    $(".printableTitle").hover(function () {
        $(this).toggleClass("hoverblue");
      });
    });
CSS:

.hoverblue { 
    background:url('images/border-bottom.png') !important;
    height:20px;
}
.hoverblueL { 
    background:url('images/border-bottom.png') !important;
    height:36px;
}
HTML:

上面所有相关的IDS看起来都像下面(但有它们的元素名称,即:(1和2)注意,.printableTitle类在<span>标签中是共享的,但是我需要定义另外两个唯一的div,因为它们需要不同的高度处理。

<li id="bostitchPrintable_1">
        <a href="http://www.canada.org" target="_blank">
            <span id="bostitchTitle_Printable_1" class="printableTitle bos_title shimify">Rollin to Canada tonight!!</span>
        </a>
    </li>

IE和Chrome完美…Firefox无法解决任何问题!!

$(window).load不能在firefox中工作,这是不好的做法。您应该使用$(document).load

如果你的jQuery版本允许,使用。on而不是。hover。

$("#bostitchTitle_Printable_1, #bostitchTitle_Printable_2").on("hover", function () {
        $(this).toggleClass("hoverblueL");
      });