日期:2014-05-16  浏览次数:20344 次

js图片轮换,超简单
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
var numb = 0;
var imgnumb = 1;
function imgfor() {
imgnumb++;
document.getElementById('img1').setAttribute('src',
'picture/' + imgnumb + '.jpg');
if (imgnumb == 9) {
imgnumb = 0;
}
}
var clearid;
function clearfun() {
window.clearInterval(clearid);
}
clearid = setInterval(imgfor, 2000);
</script>
</head>
<body>
<img alt="这是一张图" id="img1" class="style1" src="picture/1.jpg"
width="500px" height="500px" />
<br />
<input type="button" value="多张图片轮换" onclick="imgfor();" />
<br />
<input type="button" value="结束执行" onclick="clearfun();" />
</body>
</html>