0
我正在嘗試更改javascript函數內全局變量的值,但該值似乎未被採用,而且我不確定原因。 (誠然,我不是一個有經驗的JavaScript人。)這裏是我的代碼:更改全局javascript變量的值
var title_chart = "";
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Country');
data.addColumn('number', 'Number of Entries');
jQuery.getJSON('/data/stats.json', function(chart_data) {
title_chart = chart_data.chart_title;
jQuery.each(chart_data.stats, function(index, value){
data.addRows(1);
data.setValue(index, 0, value.chart_label);
});
});
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, {width: 450, height: 300, title: title_chart});
}
謝謝!
哪個全局變量?你可以說得更詳細點嗎? – 2010-07-22 05:38:03
您需要使用window.variable =「要設置的值」來設置全局JavaScript變量的值,請參閱鏈接以供參考https://www.javatpoint.com/oprweb/test.jsp?filename=jsglobalvariable2 – showmyroutes 2017-06-01 05:45:58