나는 html + javascript를 사용하는 것을 배우고 있으며, 지금은 아주 간단한 코드로 숙제를해야합니다. 이 내 HTML입니다 :간단한 자바 스크립트가로드되지 않습니다.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title> Geolocation and Local Storage and CSS3 </title>
<script type="text/javascript" src="my.js"></script>
<link rel="stylesheet" type="text/css" href="css.css" />
</head>
<body>
<div>
Location:
<button type="button" onclick="getLocation()"> Get Location </button>
</div>
<div id="holder">
</div>
</body>
</html>
이 외부 자바 스크립트입니다 :
내가 외부 파일을 제거하고 그냥 그렇게, 작동 헤드 내부에 스크립트를 넣어 얻을 경우<script>
var x = document.getElementById("holder");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
var latlon = position.coords.latitude + "," + position.coords.longitude;
var img_url = "http://maps.googleapis.com/maps/api/staticmap?center="
+latlon+"&zoom=14&size=400x300&sensor=false";
document.getElementById("holder").innerHTML = "<img src='"+img_url+"'>";
}
</script>
이상한 일이다 나는 경로가 정확하다고 생각하여 이상한 외부 파일을로드하지 않는 것으로 생각합니다.
데려가 시도 javascript 파일의 ''이 없어야합니다. – epascarello