Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
158 views
in Technique[技术] by (71.8m points)

javascript - What is the "mobile-pagecontainer" selector

jQuery Mobile has various events and methods. The pagecontainer events and methods are used to handle most of the page events from v1.4. I do not understand the use of the :mobile-pagecontainer selector.

The API documentation only uses $('.selector') which is straightforward and simple to understand though, I do not know which object it is referring to. Am I supposed to use it on a $('div[data-role="page"]') or on $('body'). And what does the other selector, :mobile-pagecontainer, signify?

API: jQuery 1.4.0 API

Edit: Also, I found many examples on stackoverflow and other websites using $(document) what is the relation to all these?

Edit 2: I created a tiny fiddle which exhibits the pagecontainerbeforeshow event using all the 3 selectors $('body'), $(':mobile-pagecontainer') and $(document)Fiddle - PageContainer Events. My heart felt gratitude and thanks to @Omar

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

$(":mobile-pagecontainer") is a selector, it refers to the parent element of jQM pages, both internal pages and external ones.

By default, :mobile-pagecontainer is body. It also can be referred to as $.mobile.pageContainer (mind capital "C" in pageContainer).

.pagecontainer() is a function that is used to change and load pages, as well as retrieve active page.

In short, $(":mobile-pagecontainer") = $.mobile.pageContainer = $("body") (default).

The value of :mobile-pagecontainer can be overridden on mobileinit, in case you want to wrap pages in a different element than body.

$(document).on("mobileinit", function () {
  $.mobile.pageContainer = $("#foo");
});
  • To change pages (assuming foo is the container):

    $("#foo").pagecontainer("change", "#pageID or URL");
    
  • To load an external page:

    $("#foo").pagecontainer("load", "URL");
    
  • To retrieve active page:

    $("#foo").pagecontainer("getActivePage");
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...