JS面向对象写法

<script type="text/javascript">
            visitNum = {
                init: function() {
                    this.bindEvent();
                    this.getVisitNum('Current');
                },
                getVisitNum: function(type) {
                    $.ajax({
                        type: "get",
                        url: "http://app.ebda.cn:8003/app/api/download/getCount",
                        data: {
                            type: type
                        },
                        timeout: 3000,
                        async: true,
                        success: function(data) {
                            visitNum.initHtml(data);
                        },
                        error: function() {
                            alert('网络出现问题,稍后重试');
                        }
                    });

                },
                initHtml: function(data) {
                    for(var i = 0; i < data.data.length; i++) {
                        var item = data.data[i];
                        var _labelType = item.labelType;
                        if(_labelType == '5') {
                            $('#fastLoginNum').html(item.count);
                        }
                        if(_labelType == '6') {
                            $('#regUserNum').html(item.count);
                        }
                        if(_labelType == 'APKDownload') {
                            $('#androidNum').html(item.count);
                        }
                        if(_labelType == 'IOSDownload') {
                            $('#iosNum').html('-');
                        }
                        if(_labelType == 'Home') {
                            $('#homeNum').html(item.count);
                        }
                        if(_labelType == 'Information') {
                            $('#infoNum').html(item.count);
                        }
                        if(_labelType == 'Robot') {
                            $('#robotNum').html(item.count);
                        }
                    }
                },
                bindEvent: function() {
                    $('.nav-left').on('click', function() {
                        $('.nav-right').removeClass('nav-active');
                        $(this).addClass('nav-active');
                        visitNum.getVisitNum('Current');
                    });
                    $('.nav-right').on('click', function() {
                        $('.nav-left').removeClass('nav-active');
                        $(this).addClass('nav-active');
                        visitNum.getVisitNum('All');
                    });
                }
            }
            visitNum.init();
        </script>

 

posted @ 2018-08-16 18:38  songjn  阅读(283)  评论(0编辑  收藏  举报