我正在学习使用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