Handle page init event for each page

Description

The following code shows how to handle page init event for each page.

Example


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.6.4.js'></script>
<script type='text/javascript'
  src="http://code.jquery.com/mobile/1.0rc1/jquery.mobile-1.0rc1.min.js"></script>
<link rel="stylesheet" type="text/css"
  href="http://code.jquery.com/mobile/1.0b3/jquery.mobile-1.0b3.min.css">
<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){<!--from  w  ww.j  a  v a2s .  c  om-->
$("#page1").live('pageinit', function () {
    $("#page1_output").append('<br/> page 1 initialized. time - ' + new Date());
});
$("#page2").live('pageinit', function () {
    $("#page2_output").append('<br/> page 2 initialized time - ' + new Date());
});
$("#page1_link").live('click', function () {
    $.mobile.changePage($("#page2"));
});
$("#page2_link").live('click', function () {
    $.mobile.changePage($("#page1"));
});
});//]]>  
</script>
</head>
<body>
  <div id="page1" data-role="page">
    <h1>One</h1>
    <a id="page1_link" data-role="button">go to page 2</a>
    <div id="page1_output"></div>
  </div>
  <div id="page2" data-role="page">
    <h1>Two</h1>
    <a id="page2_link" data-role="button">go to page 1</a>
    <div id="page2_output"></div>
  </div>
</body>
</html>

Click to view the demo





















Home »
  jQuery Mobile »
    Example »




Button
Button Event
Button Icon
Button Text
Checkbox
Collapsible
Date
Dialog
Event
Footer
Form
Header
Icon
Input
Layout
Listview
Listview Divider
Listview Item
Loader
mobile_settings
Navbar
Page
Page Event
Popup
Radio
Select
Slider
Switch
Textarea
Theme