此代码在他们的示例中运行良好,但在我尝试使用它时会重复我的一些索引项。
var lastloaded = 0;
window.onload = loadPages;
Array.prototype.knuthShuffle = function()
{
var i = this.length, j, temp;
while ( --i )
{
j = Math.floor( Math.random() * (i - 1) );
temp = this[i];
this[i] = this[j];
this[j] = temp;
}
};
var arr = ["aCard.html", "bCard.html", "cCard.html", "dCard.html"];
function loadPages () {
arr.knuthShuffle();
var frame = document.getElementById("frameWrap");
if (lastloaded+1>arr.length){
lastloaded = window.location = "greatJob.html";
}
frame.src = arr[lastloaded];
lastloaded++;
};
document.getElementById('tom').onclick = loadPages;
谁能告诉我这段代码中缺少什么以防止它重复我的数组中的项目?