简体   繁体   English

jQuery无法在加载的页面上工作

[英]Jquery Not Working on loaded page

i have a problem with jquery code. 我对jquery代码有问题。 in this case i use library high chart. 在这种情况下,我使用库高图表。 when the code put in one page there's no problem found. 当代码放在一页中时,没有发现问题。 the script running well. 该脚本运行良好。 like in this images 就像这张图片

working well 运作良好

but that's not what I want. 但这不是我想要的。 in my case i use single page apps. 就我而言,我使用单页应用程序。 and in making Single Page Apps I Use Angular JS Library. 在制作单页应用程序时,我使用Angular JS库。 nah. 不。 here's in my problem. 这是我的问题。 the jquery didn't running cause i loaded page when running page. jQuery未运行,原因是我在运行页面时加载了页面。 so. 所以。 when i click another menu the content load with another page. 当我单击另一个菜单时,内容会与另一个页面一起加载。

this is jquery script i use for using high chart library : 这是我用于使用高级图表库的jquery脚本:

    $(function () {
var chart;
$(document.body).ready(function() {
    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container', //letakan grafik di div id container
            //Type grafik, anda bisa ganti menjadi area,bar,column dan bar
            type: 'line',  
            marginRight: 130,
            marginBottom: 25
        },
        title: {
            text: 'Pendapatan perkapita indonesia tahun 2006-2011',
            x: -20 //center
        },
        subtitle: {
            text: 'candra.web.id',
            x: -20
        },
        xAxis: { //X axis menampilkan data tahun 
            categories: ['2006', '2007', '2008','2009','2010','2011']
        },
        yAxis: {
            title: {  //label yAxis
                text: 'pendapatan dalam USD'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080' //warna dari grafik line
            }]
        },
        tooltip: { 
        //fungsi tooltip, ini opsional, kegunaan dari fungsi ini 
        //akan menampikan data di titik tertentu di grafik saat mouseover
            formatter: function() {
                    return '<b>'+ this.series.name +'</b><br/>'+
                    this.x +': '+ this.y ;
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 100,
            borderWidth: 0
        },
        //series adalah data yang akan dibuatkan grafiknya,
        //saat ini mungkin anda heran, buat apa label indonesia dikanan 
        //grafik, namun fungsi label ini sangat bermanfaat jika
        //kita menggambarkan dua atau lebih grafik dalam satu chart,
        //hah, emang bisa? ya jelas bisa dong, lihat tutorial selanjutnya 
        series: [{  
            name: 'Indonesia',  
            //data yang akan ditampilkan 
            data: [1660, 1946,2271,2590,3004,3550]
        }]
    });
});

}); });

and for calling that script i use this code in html: 对于调用该脚本,我在html中使用以下代码:

  <div id="container" style="min-width: 400px; height: 400px; margin: 0 auto"></div>

please help me. 请帮我。 cause this also happen in another library. 因为这也发生在另一个库中。 Thanks 谢谢

You probably want to use an AngularJS Highcharts Adapter rather than invoking Highcharts with jQuery. 您可能想要使用AngularJS Highcharts 适配器,而不是使用jQuery调用Highcharts。

You are always going to run into problems using jQuery outside of AngularJS. 在AngularJS之外使用jQuery时,您总是会遇到问题。 In most cases jQuery should not be needed in an AngularJS SPA application. 在大多数情况下,AngularJS SPA应用程序中不需要jQuery。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM