<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<img src="img/code.png" id="affirm" alt="这是图片" title="验证码"/>
<button id="but" οnclick="show()">显示图片路径</button>
<button id="but2" οnclick="qieh()">切换图片</button>
<script>
function show() {
var affirm = document.getElementById("affirm");
var luj = affirm.getAttribute("src");
//alert(luj=="img/code.png");
if(luj=="img/code.png"){
alert(luj);
}
if(luj=="img/立即注册.png"){
alert(luj);
}
}
var affirm = document.getElementById("affirm");
var luj = affirm.getAttribute("src");
var flag = true;
function qieh () {
if(flag){
affirm.setAttribute("src","img/立即注册.png");
flag=false;
}else{
affirm.setAttribute("src","img/code.png");
flag=true;
}
}
</script>
</body>
</html>
使用js实现图片切换
最新推荐文章于 2020-09-04 15:00:32 发布