2012-06-23 143 views
0

我想使用backkey @ android手机回到某个特定页面。 我的代码(JS):onBackKeyDown获取特定页面

function onBackKeyDown() { 
    currentId = $.mobile.activePage.attr('id'); 
    if(currentId == "#swipediv"){ 
    $.mobile.changePage("#home", "slide", false, true); 
    } 
    else{ 
    history.go(-1); 
    } 
} 

HTML:

<div data-role="page" data-theme="a" id="home"> 
     <div data-role="header"><h1>Test</h1></div> 
     <div data-role="content"> 
      <p>Home</p> 
     </div> 

     </div> 
    </div> 

    <div id="swipediv"> 
     <div data-role="page" data-theme="a" id="1"> 
      <div data-role="header"><h1>1</h1></div> 
      <div data-role="content"> 
       <p>1</p> 
      </div> 
     </div> 
    </div> 

有什么不对?有什么建议么?

最好的问候

回答

0

您是否正确地添加了像这样的后退监听器?

function onDeviceReady() { 
     // Register the event listener 
     document.addEventListener("backbutton", onBackKeyDown, false); 
    } 

如果是的话,那么你检查中的PageId currentId == "#swipediv"应该没有# 这样使用

currentId == "swipediv"