为什么加载我的 html 时 map 不显示?初学者 这是我的代码
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Web Map</title>
<style type="text/css">
#map {
width: 960px;
height: 500px;
}
</style>
<link rel="stylesheet" href="css/leaflet.css" />
<script src="js/leaflet.js"> </script>
</head>
<body>
<script>
var map = L.map('map',{
center: [43.64701, -79.39425],
zoom: 15
});
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href =
"http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
</script>
<div id="map">
</div>
</body>
</html>
css源码和脚本源码来 self 的老师
最佳答案
您应该尝试将脚本移至页面底部:
<!DOCTYPE html>
<html>
<head>
<title>Leaflet Web Map</title>
<style type="text/css">
#map {
width: 960px;
height: 500px;
}
</style>
<link rel="stylesheet" href="css/leaflet.css" />
<script src="js/leaflet.js"> </script>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map('map',{
center: [43.64701, -79.39425],
zoom: 15
});
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href = "http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
</script>
</body>
</html>
关于javascript - 使用传单的 map 未使用 javascript 显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52236157/