此代码在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");
});
。