Javascript onmouseover不使用doctype在Firefox中工作? [英] Javascript onmouseover not working with doctype in firefox?

查看:234
本文介绍了Javascript onmouseover不使用doctype在Firefox中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JavaScript onmouseover事件为我的网站的菜单,但它不工作在firefox当我声明一个doctype。如果我不声明一个doctype IE显示页面错误。这是我使用的方法。

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;
}

在正文中:

    <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" />


推荐答案

Firefox不喜欢您引用图片的方式按名字。请改用Id和getElementById。

Firefox does not like the way you refer to your images by name. Use Id and getElementById instead.

编辑。注意优秀的Ben Blank的评论,由于某种原因WMD将无法正确显示在帖子中。

Edit. Notice excellent Ben Blank' comment that for some reason WMD won't correctly display in the post.

这篇关于Javascript onmouseover不使用doctype在Firefox中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆