JS对img进行操作(换图片/切图/轮换/停止)

复制代码 代码如下:


<script type="text/javascript">
var i = 1; var n;
function showImg() {
if (document.getElementById('img').getAttribute("src") == "https://www.jb51.net/images/1.jpg") {
document.getElementById('img').setAttribute("src","images/2.jpg");
}
else {
document.getElementById('img').setAttribute("src","https://www.jb51.net/images/1.jpg");
}
}
function showImg1() {
document.getElementById('img').setAttribute("src", "images/" + i + ".jpg"); i++;
if (i > 10)
{
i = 1;
}
}
function show() {
n=setInterval(showImg1, 500);
}
function show1() {
clearInterval(n);
}
</script>
</head>
<body>
<img alt="" src="https://www.jb51.net/images/1.jpg" />
<input type="button" value="换图片" />
<input type="button" value="切图" />
<input type="button" value="轮换" />
<input type="button" value="停止轮换" />
</body>
</html>

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdgxjs.html