简体   繁体   English

Javascript onmouseover无法在Firefox中使用doctype吗?

[英]Javascript onmouseover not working with doctype in firefox?

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. 我在网站上的菜单上使用了JavaScript onmouseover事件,但是在声明文档类型时在firefox中不起作用。 And if i don't declare a doctype IE displays the page wrong. 如果我不声明doctype,IE会显示错误的页面。 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" />

Firefox does not like the way you refer to your images by name. Firefox不喜欢您通过名称引用图像的方式。 Use Id and getElementById instead. 请改用Id和getElementById。

Edit. 编辑。 Notice excellent Ben Blank' comment that for some reason WMD won't correctly display in the post. 注意出色的Ben Blank的评论,由于某种原因,WMD无法正确显示在帖子中。

Ok great I got it working with javascript. 好的,很好,我使用了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 ;). 现在,我将学习正确的方法;)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM