我在使用设备 API 时遇到一个问题,问题是 device.uuid 在文档准备好后可用,而 sencha touch 在文档准备好之前加载 app.js,所以当我在 sencha 代码中使用 device.uuid 时会得到什么它显示为空
尝试通过
调用此函数<body onload="allJs();">
<script>
function allJs(){
document.write('<script src="all.js"><\/script>');
}
</script>
如果我将文档.write放在加载函数sencha应用程序之前完美加载 没有 device.uuid
<body onload="allJs();">
<script>
document.write('<script src="all.js"><\/script>');
function allJs(){
//document.write('<script src="all.js"><\/script>');
}
</script>
我该怎么办
最佳答案
使用此函数可以异步获取脚本
function lazyload() {
var scriptTag = document.createElement('script');
scriptTag.src = "//my_example.js"; // set the src attribute
scriptTag.type = 'text/javascript'; // if you have an HTML5 website you may want to comment this line out
scriptTag.async = true; // the HTML5 async attribute
var headTag = document.getElementsByTagName('head')[0];
headTag.appendChild(scriptTag);
}
以及用于phonegap或cordova的现成使用
document.addEventListener('deviceready', function(){
lazyload();
}, false);
您可以使用 jQuery getScript 函数或自己创建它,请参阅源中的链接
来源:
https://chris.lu/article/read/506de698268c420f0d000004
http://jeremyhixon.com/snippet/loading-javascript-files-asynchronously/
关于javascript - 在 deviceReady sencha touch cordova 应用程序中加载 app.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27776231/