Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 加载自定义js_Javascript_Ajax_Google Ajax Api - Fatal编程技术网

Javascript 加载自定义js

Javascript 加载自定义js,javascript,ajax,google-ajax-api,Javascript,Ajax,Google Ajax Api,我正在使用 如何加载依赖于ajaxapi加载的libs的自定义js?您可以定义一个函数,将脚本对象插入DOM中,就像 <script type="text/javascript"> function loadMyCustomJavaScript() { var script = document.createElement("script"); script.src = "http://www.example.org/my.js"; script.type =

我正在使用
如何加载依赖于ajaxapi加载的libs的自定义js?

您可以定义一个函数,将脚本对象插入DOM中,就像

<script type="text/javascript">
function loadMyCustomJavaScript() {
    var script = document.createElement("script");
    script.src = "http://www.example.org/my.js";
    script.type = "text/javascript";
   document.getElementsByTagName("head")[0].appendChild(script);
}
</script>
或者,如果您想用您加载的特定Google库加载它,作为该方法的回调,即

<script src="http://www.google.com/jsapi?key=ABCDEFG" type="text/javascript"></script>
<script type="text/javascript">
  google.load("maps", "2");
  google.load("search", "1", {"callback" : loadMyCustomJavaScript});
</script>

加载(“地图”,“2”);
load(“搜索”,“1”,“回调”:loadMyCustomJavaScript});
更新:根据您的评论,您可以尝试使用它为(外部)加载的JavaScript代码提供回调函数。根据,您可能必须使用
window.setTimeout
延迟函数的执行,直到脚本已/已评估


由于jQuery及其插件可能是异步加载的,您可能需要使用不引人注目的JavaScript,而不是直接在HTML代码中使用jQuery/plugin函数。

是的,我已经尝试过使用类似loadMyCustomJavaScript的函数,但我需要加载jQuery插件并使用它,但我不知道它们是何时加载的。我的更新对您有帮助吗?你还有什么需要知道的吗?
<script src="http://www.google.com/jsapi?key=ABCDEFG" type="text/javascript"></script>
<script type="text/javascript">
  google.load("maps", "2");
  google.load("search", "1", {"callback" : loadMyCustomJavaScript});
</script>