[英]How to print variables which are on the header on javascript?
我有以下代碼無法正常工作,我需要檢查發生了什么。 問題在於大多數代碼是在html標頭上完成的。 如何打印變量以檢查出什么問題?
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Highstock Example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$.getJSON('http://localhost/teste04.php', function(data) {
// split the data set into ohlc and volume
var ohlc = [],
volume = [],
dataLength = data.length;
for (i = 0; i < dataLength; i++) {
ohlc.push([
data[i][0], // the date
data[i][1], // open
data[i][2], // high
data[i][3], // low
data[i][4] // close
]);
volume.push([
data[i][0], // the date
data[i][5] // the volume
]);
}
// set the allowed units for data grouping
var groupingUnits = [[
'week', // unit name
[1] // allowed multiples
], [
'month',
[1, 2, 3, 4, 6]
]];
// create the chart
chart = new Highcharts.StockChart({
chart: {
renderTo: 'container',
alignTicks: false
},
rangeSelector: {
selected: 1
},
title: {
text: 'AAPL Historical'
},
yAxis: [{
title: {
text: 'OHLC'
},
height: 200,
lineWidth: 2
}, {
title: {
text: 'Volume'
},
top: 300,
height: 100,
offset: 0,
lineWidth: 2
}],
series: [{
type: 'candlestick',
name: 'AAPL',
data: ohlc,
dataGrouping: {
units: groupingUnits
}
}, {
type: 'column',
name: 'Volume',
data: volume,
yAxis: 1,
dataGrouping: {
units: groupingUnits
}
}]
});
});
});
</script>
</head>
<body>
<script src="js/highstock.js"></script>
<script src="js/modules/exporting.js"></script>
<div id="container" style="height: 500px; min-width: 500px"></div>
</body>
</html>
編輯:例如,我要打印“數據長度”。
預先感謝路易斯
作為參數回調傳遞給$ .getJSON的匿名函數內的變量僅存在於其作用域內。
您可以在該函數中使用類似console.log(dataLength)之類的內容,屆時其值將顯示在瀏覽器的控制台中。
您可以使用JavaScript調試器(firefox中的firebug,Chrome中的Javascript Console),在該函數內的第一行設置一個斷點,然后逐步執行該斷點以查看每個變量中的值。
Chrome,恕我直言,擁有最好的控制台和調試器,因此請嘗試以下操作:
$.getJSON('http://localhost/teste04.php', function(data) {
console.log(data);
// split the data set into ohlc and volume
var ohlc = [],
............
在chrome上按F12鍵,刷新頁面並在控制台中獲取數據對象內的所有值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.