JQuery Mobile:根据条件阻止changePage

时间:2013-09-04 09:01:14

标签: jquery jquery-mobile

我想根据条件(计算或服务调用的结果)阻止页面更改。

我已阅读以下链接,但在iOS设备(混合应用程序)上没有任何对我有用。

http://www.raymondcamden.com/index.cfm/2012/7/19/Preventing-navigation-to-a-page-in-jQuery-Mobile Stop all active ajax requests in jQuery http://jsfiddle.net/kiliman/zMnUM/

我的HTML看起来像:

<ul data-role="listview" data-inset="true"> 
        <li><a href="#secondPage" Onclick='change(0)' id='secBtn'>Second Page</a></li>
        <li><a href="#thirdPage" Onclick='change(1)' id='thrBtn'>Third Page</a></li> 
</ul>

在JS中,我希望实现类似的目标:

function change(val) {
if(val == 1) {
    $.mobile.changePage("#thirdPage", { transition: "slide"});
}else {
    $(document).bind("pagebeforechange", function(e ,ob) {
if(ob.toPage && (typeof ob.toPage==="string") && ob.toPage.indexOf('page.html') >=   0) {
    e.preventDefault();
    e.stopPropagation();             
    $.mobile.activePage.find('.ui-btn-active').removeClass('ui-btn-active');
      }
    });
 }

}

现在,当 e.preventDefault()被调用时,它会停止所有按钮,链接等上的所有事件。

我想只停止/运行特定按钮,LI或项目。我不知道如何实现这一点。

请提出任何建议。

0 个答案:

没有答案