






















function sort(photoes) {
var temp, j;
for (var i = 1; i < photoes.length; i++) {
if (compare(photoes[i], photoes[i - 1]) == -1) {
temp = photoes[i];
j = i - 1;
do {
photoes[j + 1] = photoes[j];
j--;
}
while (j > -1 && compare(temp, photoes[j]) == -1);
photoes[j + 1] = temp;
} //endif
}
}
function compare(p1, p2) {
var n1 = p1.src;
n1 = n1.substr(n1.lastIndexOf('/') + 1);
var n2 = p2.src;
n2 = n2.substr(n2.lastIndexOf('/') + 1);
if (n1 < n2) return -1;
if (n1 == n2) return 0;
else return 1;
}
BTW:这个例子中photos是一个html image element的数组.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。