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

时间:2013-04-17    点击:95   
复制代码 代码如下:

<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="images/1.jpg" width="200" height="200" />
<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>
JS中showModalDialog 的使用解析
中文字符串截取的js函数代码
js读写(删除)Cookie实例详解
基于dom编程中 动态创建与删除元素的使用
javaScript(JS)替换节点实现思路介绍
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved