【发布时间】:2015-05-22 21:39:36
【问题描述】:
我正在尝试创建一个 JavaScript 代码,该代码在按下按钮时显示 3 张图像,看起来它们都在向右移动。到目前为止,我对代码的 JavaScript 部分非常迷茫。我不能让它移动,或者按钮工作。
HTML:
<head>
<script src="switchright.js"> </script>
<body>
<h1 style="text-align:center">Image Switcher</h1>
<center>
<img src="../images/smile.png" id=smile>
<img src="../images/plain.png" id=plain>
<img src="../images/wink.png" id=wink>
<br>
<button type="button" id=theButton>Switch Right</button>
</center>
</body>
</head>
Javascript:
theButton.onclick = function pictureChange(){
document.getElementById('smile').src="../images/wink.png";
}
theButton.onclick = function pictureChange(){
document.getElementById('plain').src="../images/smile.png";
}
theButton.onclick = function pictureChange(){
document.getElementById('wink').src="../images/smile.png";
}
【问题讨论】:
-
每次你点击按钮时,它都会保持与它的 src 属性相同的图像。
标签: javascript html image button