js处理后台返回json格式数据生成html-列表数据

jswusn.com JS 2018-12-06 18:36:55 1432次浏览

  js处理后台返回json格式数据生成html-列表数据


$(function () {
            //点击年 重新获取数据
            $('.item-title').on('click',function () {
                $(this).addClass('title-active');
                $(this).parent().siblings().find('.item-title').removeClass('title-active');
                var case_year = $(this).find('.item-year').html();
                var cat_id = parseInt('{$cate.cid}');
                $('input.form-control').val('');
                $('#case_year').val(case_year);
//                $('.btn-number').attr('data-year',case_year);
                $.post("{:U('Common/getItem')}",{'case_year':case_year,'cat_id':cat_id},function (msg) {
                    if(msg.status ==1){
                        var data = msg.data;
                        get_ajax(data,case_year,msg.number,1)
                    }else {
                        layer.msg(msg.info);
                    }
                })
            });

            $('body').on('click','.page .btn',function () {
                var get_num = $(this).html();
                var case_year = $(this).attr('data-year');
                var cat_id = parseInt('{$cate.cid}');
                $.post("{:U('Common/getItem')}",{'case_year':case_year,'cat_id':cat_id,'get_num':get_num},function (msg) {
                    get_ajax(msg.data,case_year,msg.number,get_num);
                });
            });
            
            function get_ajax(str,case_year,number,page_num) {
                var data = str,
                    html='',
                    num,
                    num_html='',
                    active_class='';
                for(var p in data) {
                    num = parseInt(p)+1+((page_num-1)*30);
                    html += '< tr >';
                    html += '< td width="8%" class="num" >'+getnum(num,3)+'< / td >';
                    html += '< td >'+data[p].name+'< td >';
                    html += '< / tr >';
                }
//                        console.log(html);
                $('.table-responsive table').html(html);
                for(var i=1;i<=number;i++){
                    if(i==page_num) {
                        active_class = ' btn-active'
                    }
                    num_html += '< button class="btn btn-success btn-number'+active_class+'" data-year="'+case_year+'" >'+i+'< / button >';
                }
                $('.page').html(num_html);
                console.log(page_num);
            }
        })

        //搜索
        $('#search-form').ajaxForm(function(data) {
            console.log(data);
            layer.msg(data.info, {
                time: 3000
            }, function(){
                if(data.url!=''){
                    location.href=data.url
                }
            });
        });

  

  苏州网站建设专注于分享互联网、搜索引擎等互联网技术IT学习技术。

技术分享

苏南名片

  • 电话:180-0154-0762
  • 邮箱:message@jswusn.com
  • 地址:江苏省苏州市相城区

热门文章

Copyright © 2018-2020 jswusn.com 版权所有

技术支持:苏州网站建设  苏ICP备18036849号