1

我想防止基于条件(计算或服务调用的结果)的页面更改。

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

http://www.raymondcamden.com/index.cfm/2012/7/19/Preventing-navigation-to-a-page-in-jQuery-Mobile 停止 jQuery 中所有活动的 ajax 请求 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 或项目上停止/运行。我不知道如何实现这一点。

请有任何建议。

4

0 回答 0