我想通过分别点击三个按钮展示不同的图片,但没有达到效果,不知道哪里错了。有哪位js高手帮忙指导一下
<head><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><title>无标题文档</...
<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> 展开
<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> 展开
3个回答
展开全部
我写了个你试试, 这个好用。 不懂问我。
<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>
<input type="button" onClick="xx('第一张图片路径')" />
<input type="button" onClick="xx('第二张图片路径')" />
<input type="button" onClick="xx('第三张图片路径')" />
<div name="MyPic" id="MyPic" style="width:12px; height:12px;"></div>
</body>
<script type="text/javascript" language="javascript">
function xx(pr)
{
document.getElementById("MyPic").src=pr;
}
</script>
</body>
</html>
<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>
<input type="button" onClick="xx('第一张图片路径')" />
<input type="button" onClick="xx('第二张图片路径')" />
<input type="button" onClick="xx('第三张图片路径')" />
<div name="MyPic" id="MyPic" style="width:12px; height:12px;"></div>
</body>
<script type="text/javascript" language="javascript">
function xx(pr)
{
document.getElementById("MyPic").src=pr;
}
</script>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询