问题描述
$(":mobile-pagecontainer")
不起作用.我必须使用$(document)
.以下代码有什么问题吗?
$(":mobile-pagecontainer")
is not working. I have to use $(document)
.Anything wrong with the following code?
<div data-role="page" id="page1">
<div data-role="header" >
<h1>Page 1</h1>
</div>
<div role="main" class="ui-content">
This is Page1.
<a id="gotoPage2" href="#page2" class="ui-btn ui-corner-all ui-shadow ui-btn-a">Go to Page 2</a>
<script>
// not working
$( ":mobile-pagecontainer").on( "pagecontainerhide", function( event, ui ) {
alert( "page hide ");
});
// working
$( document).on( "pagecontainerhide", function( event, ui ) {
alert( "page hide " );
});
</script>
</div>
</page>
<page data-role="page" id="page2">
....
</page>
但是它可以按以下方式更改页面:
But it works for changing page as followings:
$(":mobile-pagecontainer").pagecontainer("change", "#page2", { } );
谢谢.
推荐答案
$(":mobile-pagecontainer")
是指向内部或外部所有页面的包装.默认情况下,body
是:mobile-pagecontainer
,而.pagecontainer()
是用于发出jQuery Mobile的特殊事件并用于导航的小部件.
$(":mobile-pagecontainer")
is a selector that refers to wrapper of all pages, internal or external. By default body
is :mobile-pagecontainer
and .pagecontainer()
is a widget used to emit jQuery Mobile's special events and used for navigation.
jQuery Mobile事件起泡到document
,因此您可以用来捕获这些事件.
jQuery Mobile events bubble up to document
so you can use to capture those events.
$(document).on("pagecontainershow", function (e, data) {
console.log(data.toPage); /* current active page */
console.log(data.prevPage); /* previous page */
});
如果要将事件附加到 pageconatiner ,则必须将它们包装在.ready()
中才能使它们起作用.
If you want to attach events to pageconatiner, you have to wrap them in .ready()
in order to make them work.
$(function () {
$(":mobile-pagecontainer").on("pagecontainerhide", function (e, data) {
console.log(data.toPage); /* page navigating to */
console.log(data.prevPage); /* page that was just hidden */
});
});
还可以使用窗口小部件.pagecontainer()
.
It is possible also to use the widget .pagecontainer()
.
$(":mobile-pagecontainer").pagecontainer({
hide: function (e, data) {
/* code */
},
show: function (e, data) {
/* code */
}
});
这篇关于mobile-pagecontainer:不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!