如何用javascript实现简单上下页

翻html,页面名称index.htmlpage2.htmlpage3.htmlpage4.htmlpage*.html
2025-12-05 16:26:51
推荐回答(1个)
回答1:





yugi


var array = [
            "index.html", "page2.html", "page3.html", "page4.html", "page*.html"
    ];
    onload = function ()
    {
    var div = document.querySelector ("div");
    var prev = document.querySelector ("a.prev");
    var next = document.querySelector ("a.next");
    array.index = !!array.index ? array.index : -1;
    prev.onclick = function ()
    {
     array.index--;
     array.index = array.index < 0 ? array.length - 1 : array.index;
    div.innerHTML = array[array.index];
    };
    next.onclick = function ()
    {
     array.index++;
     array.index = array.index > array.length - 1 ? 0 : array.index;
    div.innerHTML = array[array.index];
    };
    };
    // 费心劳力,采纳即可。




上一页
下一页