我要使程序实现当鼠标移向图片时,触发onmouseover事件,调用函数mouseOver()执行,程序就更换新的图片,当鼠标移出图片时,触发onmouseout事件,调用mouseOut()执行,恢复为原来的图片;另外,当按下鼠标按键时,触发body 的onmousedown事件,调用函数mousePressd(),弹出警告框。
程序如下:
<html>
<head>
<script type ="text/javascript">
function mouseOver(){
document.mouse.src ="file:///D|/我的文档/12.jpg" width="100" />
}
function mouseOut(){
document.mouse.src="file:///D|/我的文档/2.jpg" width="100" >
}
function mousePressd(event){
if (event.button= =2){
alert("您单击了鼠标右键!")
}else{
alert("您单击了鼠标左键!")
}
}
</script>
<title>无标题文档</title>
</head><body onmousedown ="mousePressd(event)">
<img border ="0" src ="file:///D|/我的文档/2.jpg" width="100" name="mouse" onmouseover ="mouseOver()" onmouseout ="mouseOut()" />
</body>
</html>

解决方案 »

  1.   


    <html>
    <head>
    <script type ="text/javascript">
    function mouseOver(){
    document.mouse.src ="last.gif" 
    }
    function mouseOut(){
    document.mouse.src="file:///D|/我的文档/2.jpg" 
    }
    function mousePressd(event){
    if (event.button==s2){
    alert("您单击了鼠标右键!")
    }else{
    alert("您单击了鼠标左键!")
    }
    }
    </script>
    <title>无标题文档</title>
    </head><body onmousedown ="mousePressd(event)">
    <img border ="0" src ="file:///D|/我的文档/2.jpg" width="100" name="mouse" onmouseover ="mouseOver()" onmouseout ="mouseOut()" />
    </body>
    </html>
      

  2.   

    <html>
    <head>
    <script type ="text/javascript">
    function mouseOver(){
    document.mouse.src ="2.jpg" 
    }
    function mouseOut(){
    document.mouse.src="1.jpg" 
    }
    function mousePressd(event){
    if (event.button==2){
    alert("您单击了鼠标右键!")
    }else{
    alert("您单击了鼠标左键!")
    }
    }
    </script>
    <title>无标题文档</title>
    </head><body onmousedown ="mousePressd(event)">
    <img border ="0" src ="1.jpg" width="236" name="mouse" onmouseover ="mouseOver()" onmouseout ="mouseOut()" height="316" />
    </body>
    </html>
      

  3.   

    1、if (event.button= =2){这行中把= =的空格去掉,改为==2、document.mouse.src ="file:///D|/我的文档/12.jpg" width="100" />这行改为
     document.mouse.src ="file:///D|/我的文档/12.jpg";3、document.mouse.src="file:///D|/我的文档/2.jpg" width="100" >这行改为
     document.mouse.src="file:///D|/我的文档/2.jpg";
      

  4.   

    上次也看了你的问题,这个= =的问题你还没有改正啊,不知道你用的是什么开发环境?建议你用FireFox浏览器,然后安装fireBug插件,这样就能调试你的代码了!上面的代码至少语法上就有错误,fireBug会给出提示错误信息!