OnMouseHover 在 Firefox 中不起作用
我做了一个简单的 onmousehover 效果,它适用于所有浏览器,但火狐浏览器除外。我已将代码精简到最低限度,但无法找出问题所在!为什么下面的鼠标悬停在 Firefox 中不起作用?
<!DOCTYPE html>
<html>
<head>
<style>
#box {
background:#222;
width:400px;
height:300px;
border-radius:5px;
}
#box_hover {
background:#555;
width:400px;
height:300px;
border-radius:5px;
}
</style>
<script type="text/jscript">
function mouseover() {
document.getElementById('box').id = 'box_hover';
}
function mouseout() {
document.getElementById("box_hover").id = 'box';
}
</script>
</head>
<body>
<div id="box" onmouseover="mouseover();" onmouseout="mouseout();"></div>
</body>
</html>
I have done an easy onmousehover effect and it works in all browsers, but firefox. I have stripped down the code to a bare minimum, but can't figure out whats wrong! Why doesn't the mouseover below work in firefox?
<!DOCTYPE html>
<html>
<head>
<style>
#box {
background:#222;
width:400px;
height:300px;
border-radius:5px;
}
#box_hover {
background:#555;
width:400px;
height:300px;
border-radius:5px;
}
</style>
<script type="text/jscript">
function mouseover() {
document.getElementById('box').id = 'box_hover';
}
function mouseout() {
document.getElementById("box_hover").id = 'box';
}
</script>
</head>
<body>
<div id="box" onmouseover="mouseover();" onmouseout="mouseout();"></div>
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Firefox 不喜欢“text/jscript”。尝试使用“text/javascript”。
Firefox doesn't like "text/jscript". Try "text/javascript" instead.
请参阅此链接现在这是工作
并且
see this link now this is work
and
除了
text/jscript
问题之外,您还可以像这样更改代码:http://jsfiddle。 net/RKKvt/请注意,
addEventListener
在旧版本的 Internet Explorer 中不起作用,您需要求助于 黑客(或完全放弃它并使用旧的元素。 onclick = function() { /* 在这里做一些事情... */ };
方式)。HTML
CSS
JavaScript
Besides the
text/jscript
issue, you can change your code like this: http://jsfiddle.net/RKKvt/Please note that
addEventListener
does not work in older versions of Internet Explorer, and you need to resort to an hack (or drop it completely and go for the oldelement.onclick = function() { /* Do something here... */ };
way).HTML
CSS
JavaScript