首页 > 代码库 > 点击按钮 变换图片
点击按钮 变换图片
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>变换图片</title>
<script type="text/javascript">
function changeImage(){
var img = window.document.getElementById("img").src;
if(img == "taohua.jpg"){
window.document.getElementById("img").src = "http://www.mamicode.com/yinghua.jpg";
}else{
window.document.getElementById("img").src = "http://www.mamicode.com/taohua.jpg";
}
}
</script>
</head>
<body>
<p> </p>
<p> <img src="http://www.mamicode.com/yinghua.jpg" width="500" height="300" id="img" /> </p>
<p>
<input type="button" value="http://www.mamicode.com/我要看桃花" onclick="changeImage();" />
</p>
</body>
</html>