我想通过分别点击三个按钮展示三张不同的图片,但没有达到效果,不知道哪里错了。有哪位高手帮忙指导一下...<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style type="text/css">
<!--
#MyPic{
width:500px;
height:400px;
border:2px solid #69F;
}
-->
</style></head><body>
<form name="MyForm">
<div>
<input name="show1" type="button" value="show1" />
<input name="show2" type="button" value="show2" />
<input name="show3" type="button" value="show3" />
</div>
<img name="MyPic" id="MyPic" src=" " />
</form>
<script type="text/javascript" language="javascript">
<!--
document.MyForm.show1.onclick=new function(){
document.images.MyPic.src="xia1.jpg"
}
document.MyForm.show2.onclick=new function(){
document.images.MyPic.src="xia2.jpg"
}
document.MyForm.show3.onclick=new function(){
document.images.MyPic.src="xia.jpg"
}-->
</script></body>
</html>

解决方案 »

  1.   

    new function  这里的new 去了
      

  2.   

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <style type="text/css">
    <!--
    #MyPic{
    width:500px;
    height:400px;
    border:2px solid #69F;
    }
    -->
    </style></head><body>
    <form name="MyForm">
    <div>
    <input name="show1" type="button" value="show1" />
    <input name="show2" type="button" value="show2" />
    <input name="show3" type="button" value="show3" />
    </div>
    <img name="MyPic" id="MyPic" src=" " />
    </form>
    <script type="text/javascript" language="javascript">
    var img = document.getElementById('MyPic');
    document.MyForm.show1.onclick=function(){
    img.src="xia1.jpg"
    }
    document.MyForm.show2.onclick=function(){
    img.src="xia2.jpg"
    }
    document.MyForm.show3.onclick=function(){
    img.src="xia.jpg"
    }</script></body>
    </html>
      

  3.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    <style type="text/css">
    <!--
    #MyPic{
    width:500px;
    height:400px;
    border:2px solid #69F;
    }
    -->
    </style></head><body>
    <form id="MyForm">
    <div>
    <input id="show1" type="button" value="show1" />
    <input id="show2" type="button" value="show2" />
    <input id="show3" type="button" value="show3" />
    </div>
    <img name="MyPic" id="MyPic" src=" " />
    </form>
    <script type="text/javascript" language="javascript">
    <!--
    var buttons=document.getElementById("MyForm").getElementsByTagName("input");
     buttons[0].onclick=function(){
    document.getElementById("MyPic").src="xia1.jpg";
    }
    buttons[1].onclick=function(){
    document.getElementById("MyPic").src="xia2.jpg";
    }
    buttons[2].onclick=function(){
    document.getElementById("MyPic").src="xia.jpg";
    }-->
    </script></body>
    </html>