【发布时间】:2013-11-22 16:33:06
【问题描述】:
我有一个 HTML5+Jquery Mobile 应用程序,我使用 PhoneGap 将 Web 视图转换为 Native android 应用程序,我编写了以下代码来退出 Mobile 上的应用程序。但此代码未退出应用程序。请帮我解决这个问题。
jQuery :
<script type="text/javascript">
$(document).on("pageinit", "#home", function (event) {
$(document).on('click', '#exit', function (e) {
if ( $('.ui-page-active').attr('id') == 'home') {
navigator.app.exitApp();
} else {
history.back();
}
}, false);
});
</script>
HTML
<div data-role="footer" data-position="fixed">
<a href="#" data-icon="back" class="ui-btn-left" data-transition="flip" data-theme="b" data-role="button" id="exit">Back</a>
<h4> </h4>
<a href="#page1" data-icon="forward" class="ui-btn-right" data-transition="flip" data-theme="b">Next</a>
</div>
【问题讨论】:
-
我没有看到任何类 ui-page-active 和 id home 的东西。你检查过这个条件好不好?
-
@Gaëtan "和 ".ui-page-active" 当前活动页面类(jquery 移动类)@Gaëtan 这样的类在页面渲染后由 jQM 动态添加。如果你添加一个console.log或者alert,它们会触发吗? 编辑: 如果是,它们将在您将
click事件绑定到paginit时触发一次。它在浏览器中触发,让我检查一下 AVD
标签: android jquery-mobile cordova