-6
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;
}

http://jsfiddle.net/z2UCX/5/

“关于”链接指向“关于”,“联系人”链接指向联系人。如何仅使用一个链接/按钮/图像使其工作,以便单个按钮循环浏览所有内容。让我们在这里使用“左按钮”而不是“主页”链接。它应该无限地保持循环链接。

4

2 回答 2

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();

于 2013-08-01T16:05:30.233 回答
0

只需要添加

var position = 0;
var list_page = new Array("home", "about", "contact");

function next_page() { 
    position = (++position)%list_page.length;   
    show(list_page[position]);
}

示例:http: //jsfiddle.net/z2UCX/10/

于 2013-08-01T16:13:09.440 回答