Javascript商店定位器,Uncaught ReferenceError:...未定义

时间:2022-06-16 07:53:38

I have set an onclick with a variable on a link that calls the calcRoute function for Google maps, and everytime I click the link it says the following Uncaught ReferenceError: NE461UL is not defined The parameter is a postcode by the way.

我在链接上设置了一个带变量的onclick,该链接调用了Google地图的calcRoute函数,每次我点击链接时都会显示以下Uncaught ReferenceError:NE461UL未定义参数是一个邮政编码。

I have been trying for a while and I can't figure out why it is showing an error.

我已经尝试了一段时间,我无法弄清楚它为什么显示错误。

I have a jquery file with the following line

我有一个带有以下行的jquery文件

var distLink = "<a onclick=\"calcRoute(" + postcode +  "); return false;\" datalat=" + lat + " datalng=" + lng + " id=\"get-directions\" class=\"directions" + letter +"\">Directions<\/a>";

The calcRoute is in my header

calcRoute在我的标题中

function calcRoute(postcode) {
  console.log(marker);
  var start = document.getElementById("address").value;
  var end = document.getElementById("get-directions").name;
 $('get-directions').click(function(){
    console.log('click!');

});
  var request = {
    origin:start,
    destination:end,
    travelMode: google.maps.TravelMode.DRIVING
  };
  console.log(JSON.stringify(request)); 
   directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      directionsDisplay.setDirections(response);
    }
  });
}

1 个解决方案

#1


2  

postcode must be passed as a string (extra pair of quotation marks around it):

邮政编码必须作为字符串传递(周围有一对额外的引号):

distLink = "<a onclick=\"calcRoute('" + postcode +  "'); return false;\" datalat=" + lat + " datalng=" + lng + " id=\"get-directions\" class=\"directions" + letter +"\">Directions<\/a>";

#1


2  

postcode must be passed as a string (extra pair of quotation marks around it):

邮政编码必须作为字符串传递(周围有一对额外的引号):

distLink = "<a onclick=\"calcRoute('" + postcode +  "'); return false;\" datalat=" + lat + " datalng=" + lng + " id=\"get-directions\" class=\"directions" + letter +"\">Directions<\/a>";