DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> 關於JavaScript >> JS對img進行操作(換圖片/切圖/輪換/停止)
JS對img進行操作(換圖片/切圖/輪換/停止)
編輯:關於JavaScript     
復制代碼 代碼如下:
<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>
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved