javascript 什么是“移动页面容器”选择器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24173871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 02:18:33  来源:igfitidea点击:

What is the "mobile-pagecontainer" selector

javascriptjqueryjquery-mobile

提问by Lordbalmon

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

jQuery Mobile 有各种事件和方法。该pagecontainer事件和方法来处理大部分的page从事件v1.4。我不明白:mobile-pagecontainer选择器的使用。

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 文档只使用了$('.selector')简单易懂的内容,我不知道它指的是哪个对象。我应该在 a$('div[data-role="page"]')或 on 上使用它吗$('body')?另一个选择器:mobile-pagecontainer, 表示什么?

API: jQuery 1.4.0 API

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?

编辑:另外,我在 stackoverflow 和其他网站上发现了很多例子,$(document)它们与所有这些有什么关系?

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

编辑2:我创建了一个微小的小提琴表现出了pagecontainerbeforeshow使用所有3个选择事件$('body')$(':mobile-pagecontainer')$(document)小提琴- PageContainer活动。我的心感谢@Omar

回答by Omar

$(":mobile-pagecontainer")is a selector, it refers to the parentelement of jQM pages, both internalpages and externalones.

$(":mobile-pagecontainer")是一个选择器,它指的是jQM页面的元素,包括内部页面和外部页面。

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

默认情况下,:mobile-pagecontainerbody。它也可以称为$.mobile.pageContainer(pageContainer 中的记大写“C”)。

.pagecontainer()is a function that is used to changeand loadpages, as well as retrieve active page.

.pagecontainer()是一个函数,用于更改加载页面,以及检索活动页面

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

总之,$(":mobile-pagecontainer")= $.mobile.pageContainer= $("body")(默认)。

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

的值:mobile-pagecontainer可以被覆盖mobileinit,以防您想用与 不同的元素包装页面body

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

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

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

    $("#foo").pagecontainer("getActivePage");
    
  • 要更改页面(假设foo是容器):

    $("#foo").pagecontainer("change", "#pageID or URL");
    
  • 加载外部页面:

    $("#foo").pagecontainer("load", "URL");
    
  • 检索活动页面

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