[英]Phonegap index.js not entering $(function(){})
这只会在设备上发生,而不会在模拟器中发生。 我可以得到第一个警报,这使我相信这不是html问题(当然,对此非常开放……)。 在weinre调试器中,我尝试复制并粘贴$(document).on函数,但是它说$(document)为null。 昨天晚上,这个工作正常,直到我不小心用libre office而不是notepad ++打开了文件。 Notepad ++将换行符显示为CR CF
,这可能与它有关吗?
编辑:我将index.html的内容复制到记事本文件中,并将其另存为html,以便摆脱任何隐藏的格式。 我还添加了jQuery作为index.html中的第一个脚本。
最后,如果查看weinre调试器中的元素,则可以看到index.html。
jQuery(document)给我ReferenceError: jQuery is not defined
因此jquery似乎出了点问题...
<script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
路径正确
答案是 ...我的蝙蝠脚本打包bin / debug /的内容仅打包文件,而不打包文件夹,因此没有js文件夹进入压缩...
先谢谢您的帮助!
window.PhotoScan = window.PhotoScan || {};
alert("we can get this far");
$(function () {
alert("how do we not get to here???!!!!!");
$(document).on("deviceready", function () {
alert("index #5");
navigator.splashscreen.hide();
if(window.devextremeaddon) {
window.devextremeaddon.setup();
}
$(document).on("backbutton", function () {
DevExpress.processHardwareBackButton();
});
});
function onNavigatingBack(e) {
if (e.isHardwareButton && !PhotoScan.app.canBack()) {
e.cancel = true;
alert("index #6");
exitApp();
}
}
function exitApp() {
switch (DevExpress.devices.real().platform) {
case "android":
navigator.app.exitApp();
break;
case "win8":
window.external.Notify("DevExpress.ExitApp");
break;
}
}
alert("index #7");
PhotoScan.app = new DevExpress.framework.html.HtmlApplication({
namespace: PhotoScan,
layoutSet: DevExpress.framework.html.layoutSets[PhotoScan.config.layoutSet],
navigation: PhotoScan.config.navigation,
commandMapping: PhotoScan.config.commandMapping
});
alert("index #8");
PhotoScan.app.router.register(":view/:id", { view: "home", id: undefined });
PhotoScan.app.on("navigatingBack", onNavigatingBack);
PhotoScan.app.navigate();
});
不知道哪里出了问题,但是通常我只是将引导程序代码包装在设备中即可。 因为我通常总是首先创建数据库模式。
document.addEventListener('deviceready', function () {
alert("index #5");
navigator.splashscreen.hide();
if(window.devextremeaddon) {
window.devextremeaddon.setup();
}
$(document).on("backbutton", function () {
DevExpress.processHardwareBackButton();
});
});
// ... your other functions here
如果要使它们不在全局范围内,可以将它们包装在一个自执行函数中:
(function() {
document.addEventListener('deviceready', function () {});
})();
我尚未在cordova应用程序中使用过准备好的文档,因为我只在底部加载了js脚本。 然后,我通过手柄栏模板和javascript加载大多数内容。
编辑
根据评论,您需要确保每次添加新文件或更改cordova项目中的文件时,都必须重新构建它:
cordova run ios --device
cordova run android
@rory,
您写了$(function(){})
这不是做事的好方法。 如果您的函数由于某种原因而失败,则您的程序将无法运行。
您打算这样做吗?
杰西
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.