onBackKeyDown获取特定页面 [英] onBackKeyDown get specific page

查看:253
本文介绍了onBackKeyDown获取特定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用backkey @ android手机回到一些特定的页面。
我的代码(JS):

I want to use the backkey @ android phones to go back to some specific page. My code(JS):

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>

有什么问题?有任何建议吗?

What's wrong ? Any suggestions?

最好的问候

推荐答案

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



如果是,则检查pageid currentId = =#swipediv应该使用
像这样

If yes then you check for the pageid currentId == "#swipediv" should be used without # Like this

currentId == "swipediv"

这篇关于onBackKeyDown获取特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆