复制代码 代码如下:
<script type="text/javascript">
var i = 1; var n;
function showImg() {
if (document.getElementById('img').getAttribute("src") == "images/1.jpg") {
document.getElementById('img').setAttribute("src","images/2.jpg");
}
else {
document.getElementById('img').setAttribute("src","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 id="img" alt="" src="/UploadFiles/2021-04-02/1.jpg"><input id="Button1" type="button" value="换图片" onclick="showImg()" />
<input id="Button2" type="button" value="切图" onclick="showImg1()" />
<input id="Button3" type="button" value="轮换" onclick="show()" />
<input id="Button4" type="button" value="停止轮换" onclick="show1()" />
</body>
</html>
<script type="text/javascript">
var i = 1; var n;
function showImg() {
if (document.getElementById('img').getAttribute("src") == "images/1.jpg") {
document.getElementById('img').setAttribute("src","images/2.jpg");
}
else {
document.getElementById('img').setAttribute("src","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 id="img" alt="" src="/UploadFiles/2021-04-02/1.jpg"><input id="Button1" type="button" value="换图片" onclick="showImg()" />
<input id="Button2" type="button" value="切图" onclick="showImg1()" />
<input id="Button3" type="button" value="轮换" onclick="show()" />
<input id="Button4" type="button" value="停止轮换" onclick="show1()" />
</body>
</html>
标签:
换图片,切图,轮换
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“JS对img进行操作(换图片/切图/轮换/停止)”评论...