2012-09-30 31 views
0

我正在處理圖像庫,並且執行了一些非常奇怪的操作,我不太明白。當我點擊我想要的「下一張圖像」或「上一張圖像」按鈕時,該按鈕就會消失,而不是顯示下一張/上一張圖像。JQuery按鈕在點擊時消失而不是激活其預期功能

I've uploaded it here, give it a go

的按鈕功能如下:

var nextbutton= $('.next'); 
var prevbutton= $('.prev'); 

nextbutton.click(function(){ 
    $(this).parent(images).hide(0).next().show(0); 
    return false; 
}); 

prevbutton.click(function(){ 
    $(this).parent(images).hide(0).prev().show(0); 
    return false; 
}); 

這是工作正常,但後來我決定再添加一個功能,一個可以讓你點擊你正在瀏覽的圖像這將然後具有與「下一張圖像」按鈕相同的功能,將您帶到下一張圖像。很簡單,我想,只是重複我用按鈕的「下一個圖像」功能,但有不同的選擇:

var imagebutton= $('#imagecontainer img:not(:last)'); 

imagebutton.click(function(){ 
    $(this).parent(images).hide(0).next().show(0); 
    return false; 
}); 

以及它的作用應該是,你點擊圖像和下一個圖像顯示。但是,現在next/prev按鈕在點擊時會消失,並且它們不會將您帶到下一個/ prev圖像。很奇怪!

我可以忽略一些明顯的東西嗎?我對JQuery相當陌生,因此非常感謝任何幫助!

+0

你能告訴什麼是imagebutton,prevbutton,nextbutton? –

+0

對不起,我會編輯文本 – bestfriendsforever

+0

爲什麼你不能使用[LightBox2](http://lokeshdhakar.com/projects/lightbox2/)? –

回答

1

雖然我不知道什麼是消失下一步按鈕的原因,試試這個代碼綁定:

$(".next, #imagecontainer img:not(:last)").on("click", function(e){ 
    $(this).closest("div").hide().next().show(); 
    e.preventDefault(); 
}); 

$(".prev").on("click", function(e){ 
    $(this).closest("div").hide().prev().show(); 
    e.preventDefault(); 
}); 

在控制檯玩你的網頁說,它可以工作。

+0

好吧,謝謝,我會給它一個! – bestfriendsforever

+0

'EYYYY它的作品!想知道那消失的按鈕是什麼?謝謝你! – bestfriendsforever