function onBackKey() {
console.log("I've caught a back key");
// We are going back to home so remove the event listener
// so the default back key behaviour will take over
document.removeEventListener("backbutton", onBackKey, false);
// Hide the current dive and show home
document.getElementById(cur).style.display = 'none';
document.getElementById('home').style.display = 'block';
cur = 'home';
}
function goToDiv(id) {
// We are moving to a new div so over ride the back button
// so when a users presses back it will show the home div
document.addEventListener("backbutton", onBackKey, false);
// Hide home and show the new div
document.getElementById('home').style.display = 'none';
document.getElementById(id).style.display = 'block';
cur = id;
}
放置html标签
<div id="home">Back Button Home<br/><a href="javascript:goToDiv('div1')">Div One</a><br/><a href="javascript:goToDiv('div2')">Div Two</a></div>
请在下面的链接中找到详细答案
https://gist.github.com/955496