gpt4 book ai didi

javascript - org.mozilla.javascript.EcmaError : ReferenceError: \"document\" is not defined

转载 作者:行者123 更新时间:2023-12-03 11:23:54 25 4
gpt4 key购买 nike

我正在使用谷歌地图来获取位置的坐标。我的代码完全按照我想要的方式运行,但是当我单击表单上的“保存”时,我收到上面标题中的错误。

谁能告诉我哪里出错了?

function init(){
//Calls the loadScript and initialize function and loads the Google Maps API
loadScript('//maps.googleapis.com/maps/api/js?APIKEY&callback=initialize');
}

function loadScript(src,callback){
//Adds the google maps script to the head of the HTML
alert('loading');
var script = document.createElement("script");
script.type = "text/javascript";
if(callback)script.onload=callback;
document.getElementsByTagName("head")[0].appendChild(script);
script.src = src;
}

最佳答案

显然我所需要的只是围绕代码进行 try catch :

function loadScript(src,callback){
//Adds the google maps script to the head of the HTML
try{
var script = document.createElement("script");
script.type = "text/javascript";
if(callback)script.onload=callback;
document.getElementsByTagName("head")[0].appendChild(script);
script.src = src;
}catch(e){
alert(e);
}
}

关于javascript - org.mozilla.javascript.EcmaError : ReferenceError: \"document\" is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26998634/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com