Javascript onmouseover 无法在 Firefox 中使用 doctype?
我在网站上的菜单中使用 JavaScript onmouseover 事件,但当我声明文档类型时,它在 Firefox 中不起作用。 如果我不声明文档类型,IE 就会显示错误的页面。 这是我使用的方法。
loadImage1 = new Image();
loadImage1.src = "http://broken.gif";
staticImage1 = new Image();
staticImage1.src = "http://broken.gif";
loadImage2 = new Image();
loadImage2.src = "http://broken.gif";
staticImage2 = new Image();
staticImage2.src = "http://broken.gif";
loadImage3 = new Image();
loadImage3.src = "http://broken.gif";
staticImage3 = new Image();
staticImage3.src = "http://broken.gif";
function showa() {
image1.src=loadImage1.src;
}
function hidea() {
image1.src=staticImage1.src;
}
function showb() {
image2.src=loadImage2.src;
}
function hideb() {
image2.src=staticImage2.src;
}
function showc() {
image3.src=loadImage3.src;
}
function hidec() {
image3.src=staticImage3.src;
}
而在身体里:
<a href="http://broken.html" onMouseOver="showa()" onmouseout="hidea()">
<img name="image1" src="http://broken.gif" alt="Browse" width="193" height="47" border="0" />
</a>
<a href="http://broken.html" onmouseover="showb()" onmouseout="hideb()">
<img name="image2" src="http://broken.gif" width="193" height="47" alt="Make a List" border="0" />
</a>
<a href="http://broken.html" onmouseover="showc()" onmouseout="hidec()">
<img name="image3" src="http://broken.gif" width="193" height="47" alt="Requests" border="0" />
</a>
</div>
<div id="searchbar">
<img src="..broken.gif" width="222" height="41" />
<img src="..broken.gif" width="108" height="41" alt="Search" />
I am using the JavaScript onmouseover event for the menu on my website, but it does not work in firefox when I declare a doctype. And if i don't declare a doctype IE displays the page wrong. Here is the method that I used.
loadImage1 = new Image();
loadImage1.src = "http://broken.gif";
staticImage1 = new Image();
staticImage1.src = "http://broken.gif";
loadImage2 = new Image();
loadImage2.src = "http://broken.gif";
staticImage2 = new Image();
staticImage2.src = "http://broken.gif";
loadImage3 = new Image();
loadImage3.src = "http://broken.gif";
staticImage3 = new Image();
staticImage3.src = "http://broken.gif";
function showa() {
image1.src=loadImage1.src;
}
function hidea() {
image1.src=staticImage1.src;
}
function showb() {
image2.src=loadImage2.src;
}
function hideb() {
image2.src=staticImage2.src;
}
function showc() {
image3.src=loadImage3.src;
}
function hidec() {
image3.src=staticImage3.src;
}
And in the body:
<a href="http://broken.html" onMouseOver="showa()" onmouseout="hidea()">
<img name="image1" src="http://broken.gif" alt="Browse" width="193" height="47" border="0" />
</a>
<a href="http://broken.html" onmouseover="showb()" onmouseout="hideb()">
<img name="image2" src="http://broken.gif" width="193" height="47" alt="Make a List" border="0" />
</a>
<a href="http://broken.html" onmouseover="showc()" onmouseout="hidec()">
<img name="image3" src="http://broken.gif" width="193" height="47" alt="Requests" border="0" />
</a>
</div>
<div id="searchbar">
<img src="..broken.gif" width="222" height="41" />
<img src="..broken.gif" width="108" height="41" alt="Search" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Firefox 不喜欢您通过名称引用图像的方式。 请改用 Id 和 getElementById。
编辑。 请注意 Ben Blank 的精彩评论,由于某种原因,WMD 无法在帖子中正确显示。
Firefox does not like the way you refer to your images by name. Use Id and getElementById instead.
Edit. Notice excellent Ben Blank' comment that for some reason WMD won't correctly display in the post.
好吧,太好了,我用 javascript 让它工作了。 我不得不说我对这个社区印象深刻,感谢您的所有帮助。 现在我要学习以正确的方式来做;)。
Ok great I got it working with javascript. I have to say I'm so impressed with this community, thanks for all your help. Now I'm going to learn to do it the right way ;).