To be or not to be.That is a question!

---源于莎士比亚的《哈姆雷特》

导航

jquery Deferred demo

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="lib/jquery.js"></script>
</head>
<body>
    <div id="demo">this is show demo</div>
    <script>
        var wait = function () {
            var defer = $.Deferred();
            var tasks = function () {
                alert('Lazy Function!');
                defer.resolve();
            }
            setTimeout(tasks, 2000);
            return defer.promise();
        };

        $.when(wait()).done(function () {console.log('success!')}).fail(function () {console.log('fail')}) 

    </script>
</body>
</html>

 

posted on 2014-04-16 12:42  Ijavascript  阅读(175)  评论(0编辑  收藏  举报