我正在使用 Phonegap 和 jQuery Mobile。这是我的代码:
function onDeviceReady() {
// Register the event listener
document.addEventListener("backbutton", onBackKeyDown, false);
setPage();
}
function setPage(){
//All pages at least 100% of viewport height
var viewPortHeight = $(window).height();
//alert(viewPortHeight );
var headerHeight = $('div[data-role="header"]').height();
var footerHeight = $('div[data-role="footer"]').height();
var contentHeight = viewPortHeight - headerHeight - footerHeight-120;
// Set all pages with class="page-content" to be at least contentHeight
$('div[class="page-content"]').css({'min-height': contentHeight + 'px'});
}
function confirmExit(){
alert("exit...");
}
// Call onDeviceReady when Cordova is loaded.
// At this point, the document has loaded but cordova-2.2.0.js has not.
// When Cordova is loaded and talking with the native device,
// it will call the event `deviceready`.
//
function onLoad() { alert("onload");
document.addEventListener("deviceready", onDeviceReady, false);
}
// Handle the back button
function onBackKeyDown() {
alert("onbackkeydown");
console.log("back clicked");
confirmExit();
}
$(document).ready(function(){});
在body标签中:
<body onload="onLoad();">
但是当我加载应用程序时,我只会在onLoad
方法中收到警报。
我做错了什么?
非常感谢。