将回调函数添加到自定义函数

时间:2014-03-10 11:05:31

标签: jquery callback fadein

我有这个HTML代码

<div class="weather">
<div id="weather"></div>
</div>

我正在使用此代码隐藏天气,然后显示fadeIn效果,但fadeIn不起作用,那么如何使用fadeIn效果显示天气div显示?

    $("#weather").weatherfeed(['SAXX0017']);
    $("select[name='weather']").change(function(){
        var city = $(this).val()
        //alert(city);
        $(".weather").fadeOut(500,function(){
            $(this).children("#weather").empty();
            $("#weather").weatherfeed([city]);
            $(".weather").fadeIn(500);
        });

    });

1 个答案:

答案 0 :(得分:1)

根据您的评论:连接到远程主机通常是通过异步调用完成的,这意味着当您调用#weather时,.fadeIn()将为空,因此动画将无法正确显示。

确保.weatherfeed()不是异步通话。如果是,则应将.fadeIn()附加到其回调中。如果不是,请尝试移动.empty()来电。

相关问题