【发布时间】:2017-04-28 05:36:02
【问题描述】:
我正在使用 Apache Cordova 制作一个 Android 应用程序。一切都可以在默认使用 Chrome 的 Android 6.0 上运行,问题出在使用默认 Android 浏览器的 Android 4.2.2 (Samsung Galaxy S4 mini) 上。
如果我没记错的话,在使用cordova编译并安装到Android操作系统后,应用程序会在默认的Android浏览器中“启动”。
在默认的 Android 浏览器中,页面加载时为空。但在 Chrome 中一切正常。
问题出在默认的 Android 4.2.2 浏览器中。它在诺基亚 1520(使用 Windows Phone 操作系统)的默认浏览器中不起作用。
index.html:
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery-3.1.1.min.js" type="text/javascript"></script>
<script src="2.js" type="text/javascript"></script>
<script src="1.js" type="text/javascript"></script>
</head>
<body>
<div id="content">
</div>
</body>
</html>
1.js:
$(document).ready(function() {
$('#content').html("<span>test3</span>"); // Works fine (i can see test3 on the page).
showLogin();
});
2.js(这个文件里面没有任何东西,我在页面上看不到 test1 和 test2):
$('#content').html("<span>test1</span>");
function showLogin() {
$('#content').html(`<span>
test2
</span>`);
}
我尝试了#1
我还尝试在setTimeout() 中调用showLogin():
setTimeout(function() {
showLogin();
}, 1000);
我尝试了#2
1.js:
$(document).ready(function() {
$('#content').html("<span>test3</span>"); // Works fine.
showLogin();
});
2.js(此文件中没有任何内容):
$(document).ready(function() {
$('#content').html("<span>test1</span>");
function showLogin() {
$('#content').html(`<span>
test2
</span>`);
}
});
【问题讨论】:
-
我觉得可以帮到你:medium.freecodecamp.com/…
-
<span>test3</span>是否在内容中正确添加?而加载页面时#content的可见值是多少? -
@maxime_039 页面加载时,#content div 为空。然后我用 HTML 登录表单填写它。
-
你不能。应该烧掉默认的安卓浏览器。
-
其他建议:(1) 将两个代码文件的
<script ...></script>行移动到body部分的底部,并从代码中删除$(document).ready,(2) 清除浏览器缓存并再次测试。
标签: javascript android jquery cordova android-browser