我正在學習使用JavaScript和HTML創建幻燈片的教程。Java腳本幻燈片
第一張圖片和「下一張」和「上一張」按鈕在頁面上,但是當我點擊下一頁或上一頁時,表示無法找到該網頁。有人能幫助我嗎?
該教程可以找到here,我還包括下面的HTML和JavaScript代碼。
的HTML代碼是:
<!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>Image Slideshow</title>
<script type="text/javascript"
src="script09.js"></script>
</head>
<body bgcolor="#FFFFFF">
<div align="center">
<h1>Welcome, Robot Overlords!</h1>
<img src="images/robot1.jpg"
id="myPicture" width="200"
height="400" alt="Slideshow" />
<h2><a href="previous.html"
id="prevLink"><<
Previous</a> <a
href="next.html" id="nextLink">Next
>></a></h2>
</div>
</body>
</html>
和JavaScript代碼是
window.onload = initLinks;
var myPix = new Array("images/robot1.jpg",
"images/robot2.jpg","images/robot3.jpg");
var thisPic = 0;
function initLinks() {
document.getElementById("prevLink").
onclick = processPrevious;
document.getElementById("nextLink").
onclick = processNext;
}
function processPrevious() {
if (thisPic == 0) {
thisPic = myPix.length;
}
thisPic--;
document.getElementById("myPicture").src =
myPix[thisPic];
return false;
}
function processNext() {
thisPic++;
if (thisPic == myPix.length) {
thisPic = 0;
}
document.getElementById("myPicture").src =
myPix[thisPic];
return false;
}
事件參數'e'添加到'processPrevious'和'processNext '函數如下:'function processPrevious(e){...}'和'function processNext(e){...}'。添加這個語句作爲每個函數的第一個語句:'e.preventDefault();'... – War10ck