我在 ie9 中遇到了这个错误,并且一直在拔头发。基本上“地图画布” div 不会加载。
这是我得到的完整错误:
SCRIPT5007:无法获取属性“offsetWidth”的值:对象为 null 或未定义 main.js,第 29 行字符 1104
任何帮助,将不胜感激!!
这是我的代码:
<!DOCTYPE html>
<html class="no-maps-mini" xmlns:v="urn:schemas-microsoft-com:vml">
<!-- Starts the HTML header area -->
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta content="text/html;charset=UTF-8" http-equiv="content-type"/>
<link rel="stylesheet" type="text/css" href="style/style.css" />
<title>Google Map Demo</title>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
var tableid1 = 4338356; //Fusion Table ID
var mylatlng = new google.maps.LatLng(49.66685, -124.91038); //map centre - Courtenay/Comox
function initialize() {
var myOptions = {
scaleControl: true,
overviewMapControl: true,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DEFAULT
},
zoom: 14,
center: mylatlng,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById('map-canvas'), myOptions);
var layer1 = new google.maps.FusionTablesLayer({
query: {
select: "'geometry'",
from: tableid1
},
map: map
});
};
function changeMapl() {
var searchString = document.getElementById('search-string-l').value.replace(/'/g, "\\'");
layerl.setOptions({
query: {
select: "'geometry'",
from: tableid1,
where: "'Name' = '" + searchString + "'"
}
});
};
google.maps.event.addDomListener(window, 'load', initialize());
</script>
</head>
<body>
<div id="container">
<div id="header">
<h1>Comox Valley Walking Trails</h1>
<hr />
</div><!-- end #header -->
<div id="content-secondary">
<h3>sidebar1 Content</h3>
<h4>Trails</h4>
<select id="search-string-l" onChange="changeMapl(this.value);">
<option value="">--Select--</option>
<option value="MacDonald Wood Park">MacDonald Wood Park</option>
<option value="Goose Spit">Goose Spit</option>
<option value="Mack Laing Park">Mack Laing Park</option>
<option value="Filberg Rd to Goose Spit">Filberg Rd to Goose Spit</option>
</select>
<div class="clear"></div>
</div>
<div id="content-primary"><div id="map-canvas"></div></div>
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats -->
<br class="clearfloat" />
<div id="footer">
<p>Footer</p>
<!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>