function show(page) {
var html = "";
switch (page) {
case "home":
html = 'All the stuff of the page ';
break;
case "about":
html = 'All the stuff of the pahe';
break;
case "contact":
html = "This is the contact page<br />...";
break;
}
document.getElementById('container').innerHTML = html;
}
'about'链接转到联系人的about和'contacts'链接。如何使用一个链接/按钮/图像使这个工作,所以一个按钮将循环通过一切。我们这里有'按钮左'而不是'主页'链接。它应该无限地保持循环链接。
答案 0 :(得分:1)
我认为你可以使用一个基本的计数器。类似的东西:
var cnt = 0;
function show() {
var html = "";
switch (cnt) {
case 0: html = "All the stuff of the page "; break;
case 1: html = "All the stuff of the page"; break;
case 2: html = "This is the contact page<br />..."; break;
}
document.getElementById("container").innerHTML = html;
cnt = (cnt+1)%3;
}
然后在您的链接中,您将调用此函数:show();
答案 1 :(得分:0)
只需要添加
var position = 0;
var list_page = new Array("home", "about", "contact");
function next_page() {
position = (++position)%list_page.length;
show(list_page[position]);
}