私はhtml + javascriptを使用することを学んでいますが、私は非常に単純なコードで宿題に固執しています。 これは私のhtmlです:シンプルなjavascriptはロードされません
<!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>
、これは外部のJavaScriptです:私は、外部ファイルを取り除くと、ちょうどそれが作品の頭の中のスクリプトを入れて取得する場合
<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