如何通过单击javascript来更改div?

时间:2018-12-19 07:38:07

标签: javascript jquery

当我单击b.js制造的a.jsp中的一项时,会调用c.js的getGrid()函数来显示另一张表。

它很好地显示了我在控制台中单击的数据。但表格grid-table-1不变。

当我单击另一个项目时,我想要的是我想再次调用getGrid以显示数据。

但是在我的代码中,只有第一次点击有效

出什么问题了?谢谢!

  itemClick: function(data){
                    getGrid(data.data.ITM_ID);
                    console.log(data.data.ITM_ID);
                }

a.jsp

 <nav>
        <ul>
            <li><a class="tri" href="javascript:void(0);" onclick="callMonth(50035);callSubtitle('살인'); this.onclick=null">살인</a></li>
            <li><a href="main.jsp"><img src="css/f4f0edb08c97567ce6b0475a63bf7000.png" alt="Italian Trulli" width="40px" height="25px"></img></a></li>
            <li><a href="javascript:void(0);" onclick="callMonth(50035); callSubtitle('살인');">살인</a></li>

        </ul>
    </nav>
 <div class="wrap">
                <h3>등락율 순위</h3>
                <table id="grid-table-1">

                </table>
            </div>

b.js

  function callMonth(num) {

$.ajax({
    url     : 'http://www.crimestats.or.kr/openapi/Sttsapitbldata.do?KEY=373f2cc31cd449c992cc18004780f4e4&STATBL_ID=T184223019918177&DTACYCLE_CD=YY&WRTTIME_IDTFR_ID=2016&Type=json&CLS_ID='+num,
    type    : 'GET',
    dataType: 'json',
    success : function (resp) {
        $(".chart01").html("");
        console.log(resp);


        var options = {
            data  : {
                data: []

            },
            format: {
                xAxis: function (_str) {
                    return _str.substr(0, 4);
                },
                yAxis: 'priceDataFormat'
            },
            func  : {
                tip: function (tipElement, data, rect) {
                    //console.log(data)
                    var date = data.xaxis.substr(0, 4);
                    var tip = '<div class="text">' + date + ' / ' + String(data.yaxis).format().trim() + '</div>';

                    tipElement.html(tip).show();

                    var arrow = '<div class="arrow" style="width: ' + tipElement.width() + 'px;"></div>';

                    tipElement.html(tipElement.html() + arrow).css({
                        left: rect.x - (tipElement.width() / 2), top: rect.y - 35
                    });

                },
                itemClick: function(data){
                    getGrid(data.data.ITM_ID);
                    console.log(data.data.ITM_ID);
                }
            },
            use   : {
                animate   : true,
                aCrossLine: true
            }

        };
        var rows = resp.Sttsapitbldata[1].row;
        if (rows) {
            var representativeRow;
            for (i = 1; i < 13; i++) {
                representativeRow = rows[i];
                itemNm2 = representativeRow.ITM_NM;
                dataV = representativeRow.DTA_VAL;
                itm_id= representativeRow.ITM_ID;
             /*   console.log(itemNm2);
                console.log(dataV);
                console.log(itm_id);*/
                options.data.data.push({DTA_VAL: dataV, ITM_NM: itemNm2, ITM_ID:itm_id});

            }

            var series = {
                "main": {
                    "s1": {series: 'column', xaxis: 'ITM_NM', yaxis: 'DTA_VAL'}
                }
            };
            event.stopPropagation();
            var chart = webponent.chart.init($('.chart01'), options, styles, series);
        }
    }, /*error: function (xhr, status, error) {
    alert("err")
}*/
});

}

c.js

function getGrid(itm_id_num) {
    $(".grid-table-1").html("");
    var table1 = $('#grid-table-1');
    var template1 = $('#grid-template-1');
    var grid1 = webponent.grid.init(table1, template1);
    var body = [];

    $.ajax({
        dataType: 'json',
        url     : 'http://www.crimestats.or.kr/openapi/Sttsapitbldata.do?KEY=373f2cc31cd449c992cc18004780f4e4&STATBL_ID=T184223019918177&DTACYCLE_CD=YY&WRTTIME_IDTFR_ID=2016&Type=json&ITM_ID='+itm_id_num,
        success : function (resp) {

            var options = {
                data: {
                    data: []
                }
            };
            var rows = resp.Sttsapitbldata[1].row;
            //console.log(rows);
            if (rows) {
                var representativeRow;
                for (i = 11; i < 100; i++) {
                    representativeRow = rows[i];
                    itemNm2 = representativeRow.ITM_NM;
                    dataV = representativeRow.DTA_VAL;
                    stable_id = representativeRow.STATBL_ID;
                    cls_nm = representativeRow.CLS_NM;
                    cls_id = representativeRow.CLS_ID;
                    /* console.log(itemNm2);
                     console.log(dataV);*/


                    options.data.data.push({
                        ITM_NM   : itemNm2,
                        STATBL_ID: stable_id,
                        CLS_NM   : cls_nm,
                        CLS_ID   : cls_id,
                        DTA_VAL  : dataV
                    });

                }
                grid1.appendRow(options.data.data);
            }

           }
    });

}

0 个答案:

没有答案