Jquery Mobile Back Buttons

后端 未结 1 944
借酒劲吻你
借酒劲吻你 2021-01-25 18:02

I have an application in which I am programmatically add a back button to the page. This means that the first page will not have a back button on it. However the app itself has

相关标签:
1条回答
  • 2021-01-25 18:33

    I assume that you're using data-add-back-btn=true to dynamically add data-rel=back buttons to your pages. Hence, it is possible by first, checking if there is no data-rel=back in the active page and secondly, it is not your Home page.

    One more thing, you need to remove that button once you navigate away from that page in order not to overlap with the one that JQM will generate.

    Demo

    var backbtn = '<a href="#home" data-icon="arrow-l" data-iconpos="notext" class="backbtn"></a>';
    
    $(document).on('pagebeforeshow', function () {
     var activePage = $.mobile.activePage;
     if (activePage.find('[data-rel=back]').length === 0 && activePage[0].id != 'home') {
      activePage.find('[data-role=header] h1').before(backbtn);
     }
     $('[data-role=page]').trigger('pagecreate');
     $(document).on('pagebeforehide', function () {
      $('a.backbtn').remove();
     });
    });
    
    0 讨论(0)
提交回复
热议问题