Jquery $.mobile.activePage属性究竟是如何工作的?

Jquery $.mobile.activePage属性究竟是如何工作的?,jquery,jquery-mobile,Jquery,Jquery Mobile,我试着做如下的事情 $(document).bind ('pageshow', function (e, data) { console.log ($('#page_spots')); console.log ($.mobile.activePage); if ($.mobile.activePage == $('#page_spots')) { console.log ('Bingo!'); } }); 作为#page_点一个div,其属性数据角色设置为页面。在上面的示例

我试着做如下的事情

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

   if ($.mobile.activePage == $('#page_spots')) { console.log ('Bingo!'); }
});
作为
#page_点
一个div,其属性
数据角色
设置为
页面
。在上面的示例中,当活动页面为
#page_spots
时,我想记录“宾果!”在控制台中

我是jQM的新手,我不知道这是否是正确的方法


提前感谢您并为我的英语道歉。

您可以从
$.mobile.activePage
获取活动页面的ID,并将其与字符串进行比较,而不是尝试与jQuery对象进行比较:

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

   if ($.mobile.activePage.attr('id') == 'page_spots') { console.log ('Bingo!'); }
});
下面是一个演示:

$.mobile.activePage
很好,因为它始终是当前
数据role=“page”
元素的缓存对象,可以快速引用

更新


我刚刚又读了一遍,您不需要使用
.attr()
来查找ID,您可以通过直接从DomeElement访问属性来更快一点:
$.mobile.activePage[0]。ID

谢谢Jasper!我还不能接受你的回答,但我会在2分钟内回答。