简体   繁体   English

如何引用 HTML 中的函数?

[英]How to refer to a function in HTML?

I am making an html file that basically prints out the coordinates given by the user in a map.我正在制作一个 html 文件,它基本上打印出用户在地图中给出的坐标。 Whenever I click the submit button, it returns me an error of "UncaughtReferenceError: NewMap is not defined" i tried using an external javascript and inline javascript but it does not seem to solve the problem.每当我单击提交按钮时,它都会向我返回“UncaughtReferenceError:NewMap 未定义”的错误,我尝试使用外部 javascript 和内联 javascript 但它似乎没有解决问题。 Can you tell me what is wrong with the code?你能告诉我代码有什么问题吗?

<!DOCTYPE html>
<html>
<head>
<title>Find My Phone</title>
</head>
<body bgcolor="#2196F3">
<p style="font-size:150%; text-align:center">This is the extension for the app FindMyPhone. In this site, you can view the coordinates where your phone was traced on a map</p>
Latitude:
<input type="number" step="any" id="Lat"/> <br>
Longitude:
<input type="number" step="any" id="Lng"/> <br>
<button onclick="NewMap()">Submit</button>
<div id="map" style="height:500px;width:500px; color:#9E9E9E">
</div>
<script>
function NewMap() {
   var mapCanvas = document.getElementById("map").value;
   var Latitude = document.getElementById("Lat").value;
   var Longitude = document.getElementById("Lng").value;
   var mapOptions = {
    center: document.getElementById("Lat, Lng")
    zoom:15
   }
   var map = new.google.maps.Map (mapCanvas, mapOptions)
  }
 </script>

 </body>
 </html>

PS: Supposing this code works, will it output the map correctly? PS:假设这段代码有效,它会正确输出地图吗? Please also show me if it is right or wrong.还请告诉我它是对还是错。

  1. Include Google Map Library包括谷歌地图库

  2. You have missed out a comma after center property.您在 center 属性后遗漏了一个逗号。

    var mapOptions = { center: document.getElementById("Lat, Lng"), zoom:15 } var mapOptions = { center: document.getElementById("Lat, Lng"), zoom:15 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM