我正试图从这个website开始围绕脚本加载,但是不理解关于如何将脚本添加到脚本中以使脚本可按需访问的部分。浏览器无法向后读取代码,那么当浏览器已经读完并评估了代码时,将头文添加到head标记的重点是什么?很抱歉,如果我使用错误的术语,但我对浏览器的理解是它通过链接从上到下读取html行,所以对底部(在body标签中)添加的内容没有意义它上面的东西(在头部标签中),当它已经通过那个区域时执行它。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example</title>
<!-- script is added here but this part of the page has already been read by the browser already so how can it make a difference? -->
</head>
<body>
<script type="text/javascript">
// need something from www.url.com so create script on demand
var head = document.getElementsByTagName('head')[0],
script = document.createElement('script');
script.src = www.url.com;
head.appendChild(script);
// use the thing I just got from www.url.com
</script>
</body>
</html>