我的代码工作正常,但我想通过将整个 Javascript 放在另一个文件(如maps.js
. 但maps.js
不承认与线。使用 Firebug,我尝试调试并发现该文件的 GET 失败!
但是 GET 适用于socket.io.js
. 我通过 localhost:8080 使用 node.js 运行系统。谁能告诉我我在这里做错了什么?或者当 HTML 代码被执行时,当前工作目录实际上在哪里?我什至尝试了 的绝对路径maps.js
,但没有任何成功。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta type="keywords" content="" />
<link href="/maps/documentation/javascript/examples/default.css" rel="stylesheet">
<title>ReSense Client</title>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="/js/maps.js"></script>
<script type="text/javascript">
var socket = io.connect('http://localhost');
var stockholm = new google.maps.LatLng(59.32522, 18.07002);
var parliament = new google.maps.LatLng(59.327383, 18.06747);
var marker;
var map;
function initialize() {
var mapOptions = {
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: stockholm
};
map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
google.maps.event.addListener(marker, 'click', toggleBounce);
}
function toggleBounce() {
if (marker.getAnimation() != null) {
marker.setAnimation(null);
} else {
marker.setAnimation(google.maps.Animation.BOUNCE);
}
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width: 500px; height: 400px;">map div</div>
</body>
</html>