2012-05-23 137 views
2

下面兩個函數的工作原理是腳本化的,除了當我在其周圍添加函數next(){;}和函數prev(){'}來定義自定義函數時。定義jQuery函數

我在這裏做錯了什麼?

function next() { 

     $('#up').click(function() { 
     $("#two").prev().animate({height:'80%'}, 500); 
     }); 
    ;} 


    function prev() {  
     $('#down').click(function() { 
     $("#two").next().animate({height:'80%'}, 500); 
     }); 
;} 
+2

這是一個壞習慣惹使用prev(),next()將是等於例如jQuery的函數名名左右,改變你的名字別的東西然後再試一次。 – Gustav

+0

及以上@gustav建議,你也需要調用這些函數,以綁定事件 – fcalderan

回答

11

你在功能分配click事件,你的意思是呼籲點擊事件的功能?嘗試:

$(function() { 
    $('#up').click(next); 
    $('#down').click(prev); 
}); 

function next() { 
    $("#two").prev().animate({height:'80%'}, 500); 
;} 

function prev() {  
    $("#two").next().animate({height:'80%'}, 500); 
;} 
+1

你打我:) –

+0

@Martin hehe對不起哥們:) – mattytommo

+0

是啊我只是來到它,它的功能需要被調用.click() 謝謝@mattytommo和@martin! –

-3

你不能給

height:'80%' 

它應該是:

height:'80' 

'%' 是不允許的。

+0

這是一個謊言... –

+0

是的,它與%在那裏工作。這是不好的做法,使用%? –

+0

@Joe不,沒關係 –

0

它會工作,也可以後 $("#two").animate({height:'80%'}, 500);