【发布时间】:2013-07-03 10:46:04
【问题描述】:
我有一段 Javascript 代码可以在 Chrome 和 Firefox 中运行,但在 IE 中无法运行。该代码应该在鼠标悬停某个 div 时更改 CSS 背景图像,并在鼠标离开时删除背景图像。
Javascript:
$(document).ready(function() {
$('.expositores1').hover(function() {
$('.expositores1').css('background-image', 'url(/wp-content/themes/kallyas/images/mapa/piso0/inter_piso0_r5_c2_f4.jpg)', 'background-repeat', 'no-repeat');
$('.expositores2').css('background-image', 'url(/wp-content/themes/kallyas/images/mapa/piso0/inter_piso0_r12_c2_f2.jpg)', 'background-repeat', 'no-repeat');
$('.expositores3').css('background-image', 'url(/wp-content/themes/kallyas/images/mapa/piso0/inter_piso0_r12_c4_f2.jpg)', 'background-repeat', 'no-repeat');
$('.expositores4').css('background-image', 'url(/wp-content/themes/kallyas/images/mapa/piso0/inter_piso0_r14_c3_f2.jpg)', 'background-repeat', 'no-repeat');
});
$('.expositores1').mouseout(function() {
$('.expositores1').css('background-image', 'none');
$('.expositores2').css('background-image', 'none');
$('.expositores3').css('background-image', 'none');
$('.expositores4').css('background-image', 'none');
});
});
HTML:
<div class="expositores1"></div>
<div class="expositores2"></div>
<div class="expositores3"></div>
<div class="expositores4"></div>
CSS:
.expositores1{
position: absolute;
width: 306px;
height: 122px;
margin-left: 11px;
margin-top: 146px;
}
.expositores2{
position: absolute;
width: 81px;
height: 127px;
margin-left: 11px;
margin-top: 268px;
}
.expositores3{
position: absolute;
width: 185px;
height: 127px;
margin-left: 132px;
margin-top: 268px;
}
.expositores4{
position: absolute;
width: 40px;
height: 90px;
margin-left: 92px;
margin-top: 304px;
}
有人可以帮忙吗?为什么它在 Chrome 和 Firefox 中有效,而在 IE 中无效?
问候, 雨果
【问题讨论】:
-
当你说不工作时,哪个部分不工作?有没有看到图片,是鼠标悬停还是鼠标移出的问题?
-
到目前为止,您尝试过哪些版本的 IE?
-
我使用的是 IE10。不起作用的是悬停。所以,我是悬停 div 并且背景图像没有改变。
-
你为什么使用
.hover()和.mouseout()? (它们不是对立的——如果你将一个函数传递给.hover(),它将在鼠标进入和离开时被调用。) -
除了你的问题,你应该检查编码风格。您不应该对所有这些 $('.expositoresX') 进行硬编码。创建一个从第二个元素开始的循环或其他东西。
标签: javascript html internet-explorer