这是一个创建面包屑的函数。它最初来自其他人,但我已经对其进行了调整以满足我的需要。现在——我想修复'for(i in bits)'的错误语法,但是当我尝试了我认为可行的方法时,它不起作用。
for (i = 0; i < bits; i++) {etc...};
我以为这行得通,它行不通。这是完整的脚本...
function breadcrumbs() {
'use strict';
/*jslint plusplus:true*/
/*jslint browser:true*/
var sURL, bits, x, stop, output, i, y, chunkStart;
sURL = String();
bits = {};
x = 0;
stop = 0;
output = "";
sURL = location.href;
sURL = sURL.slice(8, sURL.length);
chunkStart = sURL.indexOf("/");
sURL = sURL.slice(chunkStart + 1, sURL.length);
while (!stop) {
chunkStart = sURL.indexOf("/");
if (chunkStart !== -1) {
bits[x] = sURL.slice(0, chunkStart);
sURL = sURL.slice(chunkStart + 1, sURL.length);
} else {
stop = 1;
}
x++;
}
for (i in bits) {
output += "<a href=\"";
for (y = 1; y < x - i; y++) {
output += "../";
}
bits[i] = decodeURIComponent(bits[i]);
output += bits[i] + "/\">" + bits[i] + "</a> | ";
}
document.write(output + document.title);
}