jQuery Mobile pagecreate event
Example
Pop up a message when the page is initialized, before enhancement is complete:
$(document).on("pagecreate",function(){
alert("pagecreate event triggered!")
});
Try it »
Definition and Usage
pagecreate is an event triggered after a page is successfully created, but before jQuery Mobile finishes enhancing the page.
Note: This event can only be triggered once per page - when the page is first loaded, jQuery Mobile caches the page in the DOM (memory), so when you navigate back from a second page to the first page through the browser, this event will not be triggered, because the first page has already been initialized.
**Note:** Before version 1.4, we used the pageinit event (deprecated) to handle this.
Tip: This event is typically used when a user wants to enhance custom components:
$(document).on("pagecreate","#pagetwo",function(event){
$.(":jqmData(role='my-plugin')").myPlugin();
});
Related events:
- pagebeforecreate - Triggered after the page is initialized, but before the page is enhanced.
- pageinit - Triggered after the page has been fully initialized and enhanced.
Syntax
Trigger the event for all pages in jQuery Mobile:
$("document").on("pagecreate",function(event){...})
Try it
Trigger the event for a specified page:
$("document").on("pagecreate","
page
",function(event){...})
Try it
| Parameters | Description |
|---|---|
| function(event) | Required. Specifies the function to execute when the pagecreate event is triggered. |
函数有一个可选事件对象, 可以保护任何的jQuery事件属性 (event.target, event.type, 等。 查看更多信息请查阅 [jQuery 事件参考手册](/jquery/jquery-ref-events.html) 。 |
| page | Optional. Used to specify the id of the page the pagebeforecreate event points to. For internal pages, use #id. For external pages, use externalfile.html. |
More examples
pagebeforecreate and pagecreate event examples
This example demonstrates the triggering of the pagebeforecreate and pagecreate events.
Event Object
Use the event.type property to return the type of event that was triggered.
jQuery Mobile Events