您的位置:首页 > Web前端 > JavaScript

js点击按钮更改html页面的图片(两个来回换)

2017-12-08 10:05 405 查看
<!DOCTYPE html>
<html>
<body>

<img id="image" src="111.png" onmousedown="secound(this)" onmouseup="first(this)">
<button onclick="change()">点击换图片</button>
<script>
function change() {
var x = document.getElementById("image").getAttribute("src");

if (x=="111.png"){
document.getElementById("image").src="222.png";
}
else{
document.getElementById("image").src="111.png";
}
//alert(x);
}

function secound(obj){
obj.src="222.png";
console.log(obj.getAttribute("src"));
}

function first(obj){
obj.src="111.png";
console.log(obj.getAttribute("src"));
}
</script>

</body>
</html>


这里是我们的图片





 页面效果: http://shuaishuaicloud.cn/4444.mp4 
 

(我的腾讯云主机) 可能到2018 6 就不能用了那时我已毕业 


点击打开链接
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  web js
相关文章推荐