定义JQuery函数

时间:2012-05-23 11:27:51

标签: javascript jquery html css function

以下两个函数作为脚本工作,除非我在其周围添加函数next(){;}和函数prev(){'}来定义自定义函数。

我在这里做错了什么?

function next() {

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


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

3 个答案:

答案 0 :(得分:11)

您在该函数中分配了click事件,您是不是要在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)

它会起作用,你也可以使用prev(),next()之后     $("#two").animate({height:'80%'}, 500);

答案 2 :(得分:-3)

你不能给予

height:'80%'

它应该是:

height:'80'

'%'是不允许的。

相关问题