我有以下带有 jquery 脚本的 html 页面。IE8 中的脚本在以下行中失败:
var dataCopy = JSONObject[event];
for (data in dataCopy)
我收到的错误消息是:“对象不支持此属性或方法”。相同的代码在 Chrome 和 Firefox 中运行良好。任何建议都会很棒。我正在尝试获取所有不同的年份值。
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>
Google Visualization API Sample
</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script src="..\Scripts\jquery-1.7.1.js" type="text/javascript"></script>
<script type="text/javascript">
google.load('visualization', '1', {packages: ['corechart', 'geochart', 'table'] });
</script>
<script type="text/javascript">
function drawVisualization() {
var JSONObject = {
cols: [{
id: 'Year', label: 'Year', type: 'string'
},{
id: 'data1', label: 'col2', type: 'number'
},{
id: 'data2', label: 'col3', type: 'number'
}],
rows: [{
c:[{v: '2000'}, {v: null}, {v: 3}]
},{
c:[{v: '2001'}, {v: 8}, {v:3 }]
},{
c:[{v: '2004'}, {v: 2.1244322}, {v: 4}]
}
]};
var yearArray = [];
for (var event in JSONObject) {
var dataCopy = JSONObject[event];
for (data in dataCopy) {
var mainData = dataCopy[data];
for (key in mainData) {
if (key.match(/c/)) {
var row = mainData[key];
yearArray.push(row[0].v);
}
}
}
}
alert(yearArray.length);
}
</script>