jQuery 的语法错误

Syntaxic error with jQuery

我尝试使用 jQuery .toggle().animate() 函数对 2 个动画进行排队,但它 returns 是一个语法错误,就像我忘记了 }...

但我看不到哪里,对我来说一切似乎都很好...... 任何人有任何线索?或者也许是一种更好的方法来做我正在尝试做的事情?我试着让一个跨度交替上升和下降。

代码如下:

<script type="text/javascript">
    jQuery(document).ready(function($){
        $('body').prepend('<div id="vamos-abajo"><span></span></div>');
        $('#vamos-abajo span').toggle(function(){
            $(this).animate({top:"10px";}, 250);
        },function(){
            $(this).animate({top:"0px";}, 500);
        });
    });
</script>

问题出在您的动画中的分号 (;)。该部分需要如下所示:

 $(this).animate({top:"10px"}, 250);

或者,如果您要同时为多个 CSS 属性设置动画,您可以使用逗号

 $(this).animate({top:"10px", left:"15px"}, 250);