在谷歌的Chrome浏览器中运行我的(相当复杂的)JavaScript / jQuery应用程序,似乎$(document).ready
会在某些JavaScript文件尚未加载时触发。
相关代码(简化):
在我的HTML文件中
<script>var httpRoot='../../../';var verifyLoad = {};</script>
<script src="../../../globalvars.js"></script>
<script src="../../../storagekeys.js"></script>
<script src="../../../geometry.js"></script>
<script src="../../../md5.js"></script>
<script src="../../../serialize.js"></script>
...
<script src="../../../main.js"></script>
作为除main.js之外的每个.js文件的最后一个语句:
verifyLoad.FOO = true; // where FOO is a property specific to the file
e.g。
verifyLoad.jquerySupplements = true;
verifyLoad.serialize = true;
在main.js中:
$(document).ready(function() {
function verifyLoadTest (scriptFileName, token) {
if (!verifyLoad.hasOwnProperty(token)) {
console.log(scriptFileName + ' not properly loaded');
};
};
verifyLoadTest('globalvars.js', 'globalvars');
verifyLoadTest('storagekeys.js', 'storagekeys');
verifyLoadTest('geometry.js', 'geometry');
verifyLoadTest('md5.js', 'geometry');
verifyLoadTest('serialize.js', 'serialize');
...
}
令我惊讶的是,我看到其中一些触发器。这与我对$(document).ready
的理解不符。我错过了什么?