首页 > 代码库 > 经典JavaScript 样例

经典JavaScript 样例

1.animate 实现动画效果的JavaScript脚本: 

<script type="text/javascript">
        $(function () {
            $("span").animate({
                left: "+=100px"
            }, 3000, function () {
                $(this).animate({
                    height: ‘+=30px‘,
                    width: ‘+=30px‘
                }, 3000, function () {
                    $("#tip").html("执行完成!");
                });
            });
        });
    </script>

2.JSON数据格式的解析:

    <script type="text/javascript">
        $(function () {
            $("#btnShow").bind("click", function () {
                var $this = $(this);
                $.getJSON("http://www.imooc.com/data/sport.json",function(data)
                {
                    $this.attr("disabled", "true");
                    $.each(data, function (index, sport) {
                        if(index==3)
                        $("ul").append("<li>" + sport["name"] + "</li>");
                    });

                });
            })
        });
    </script>

经典JavaScript 样例