简体   繁体   English

未加载库时如何调试参考错误?

[英]How to debug reference error when a library is not being loaded?

For example I am getting a reference error L is not defined where L is leaflet. 例如,我得到的reference error L is not defined ,其中L是小叶。 I have followed their tutorial , and here is what I have just before the end of my body: 我已经按照他们的教程进行了学习 ,这是我刚结束时的内容:

<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script>
    var map = L.map('map').setView([51.505, -0.09], 13);
    L.tileLayer('http://{s}.tiles.mapbox.com/v4/secretid/{z}/{x}/{y}.png', {
      attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
      maxZoom: 18
    }).addTo(map);
</script>

I've checked and the hyperlink to the js file works. 我已经检查过,并且指向js文件的超链接有效。

To be sure all script have already loaded, use onload callback like this: 为了确保所有脚本都已经加载,请使用如下的onload回调:

<script>
    window.onload = function() {
     var map = L.map('map').setView([51.505, -0.09], 13);
     L.tileLayer('http://{s}.tiles.mapbox.com/v4/secretid/{z}/{x}/{y}.png', {
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a     href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a     href="http://mapbox.com">Mapbox</a>',
 maxZoom: 18
    }).addTo(map);
}
</script>

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

相关问题 如何调试角度库错误? - How to debug angular library error? 当包含在gwt.xml中时如何跳过加载外部JavaScript库? - How skip loading external JavaScript library from being loaded when included in gwt.xml? 动态加载JS库时出现“未定义”错误 - “Not defined” error when JS library loaded dynamically 如何调试? ZeroClipboard加载无错误并发出警告,但未复制 - How to debug? ZeroClipboard loaded no error&warning but not copying 当document.write加载JavaScript代码时,如何调试它? - How to Debug a JavaScript code when it is loaded by document.write? 加载javascript时如何在vue组件中引用javascript中的img - How to reference img in javascript in a vue component when it is loaded with javascript 如何在加载大图像时显示加载图像? - How to show loading image when a big image is being loaded? 如何在我的组件加载时停止检索数据 - How to stop data being retrieved when my component is loaded 在外部库中调用函数时引用错误 - 仅限firefox - Reference error when calling function in external library - firefox only 我可以检测到JavaScript是否未最小化地加载(作为调试模式) - Can I detect that javascript is being loaded unminified (as debug mode)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM