How exactly does $.mobile.activePage property work?

后端 未结 1 905
后悔当初
后悔当初 2021-02-14 13:47

I am trying something as follows,

$(document).bind (\'pageshow\', function (e, data) {
   console.log ($(\'#page_spots\'));
   console.log ($.mobile.activePage);         


        
相关标签:
1条回答
  • 2021-02-14 14:22

    You can get the active page's ID from $.mobile.activePage and compare it to a string rather than trying to compare to a jQuery object:

    $(document).bind ('pageshow', function (e, data) {
       console.log ($('#page_spots'));
       console.log ($.mobile.activePage);
    
       if ($.mobile.activePage.attr('id') == 'page_spots') { console.log ('Bingo!'); }
    });
    

    Here is a demo: http://jsfiddle.net/E6YuA/

    $.mobile.activePage is nice to have because it is always a cached object of the current data-role="page" element that you can quickly reference.

    Update

    I was just reading this again and you don't need to use .attr() to find the ID, you can a bit more quickly by accessing the attribute directly from the DOMElement: $.mobile.activePage[0].id

    0 讨论(0)
提交回复
热议问题