function removeImage(element, event){
var albumHolder = document.getElementById('album');
albumHolder.removeChild(element);
event.preventDefault();
currPhotoId = element.id.split("_");
// This should be a bit simpler
album[currPhotoId].disabled = true;
console.log(album);
}
然後...
function disabledCheck(currentID, direction)
if(album[currentID].disabled){
// search for next one which isn't disabled in next or previous direction
}else{
return currentID
}
,如果你想跳過這個元素,並搜索下一個沒有-disabled one
function disabledCheck(currentID, direction)
for(var i = 0; i < (album.length - currentID))
{
if(album[currentID].disabled){
// search for next one which isn't disabled in next or previous direction
continue;
}else{
return currentID
}
i++;
}
謝謝,我設法調整它一點點,所以它給了我想要的輸出:D你是我的英雄! – 2012-03-05 20:12:39
您可以將功能添加到相冊的任何實例以支持多個相冊:例如, 'album.getNext = getNext'。如果你希望它是一個完全孤立的函數,你需要傳入當前的索引和一個對專輯的引用來迭代,否則它將無法確定下一個/前一個是否被禁用。在這種情況下,一個'album'參數,並將body中'this.album'的每個實例更改爲'album',並且'currPhotoId'也一樣。 – devios1 2012-03-05 20:18:01