$(document).on('pageinit
pagechange pageshow',
function()
{
alert('here');
}
});
This will fire on ANY
pageinit
,
pagechage
or
pageshow
. Did you want to do
something different?
For example, you can
use delegation to do something when a particular page (or pages)
are initialized:
$(document).on('pageinit',
'.some-page-selector', function() {
var $page =
$(this); // handy variable to have
// Do
something when any page with class some-page-selector is initialized
});
Please read
the documentation on jQuery Mobile Ajax page loading. It's
useful to observe the DOM using your browser's inspection
features. (Web Inspector, Chrome Dev Tools, etc.)
So much of conventional web
front-end programming depends on the fact that the document is
normally reloaded when you load a "page".) (HTML really
has no such thing as a "page"!) Everything starts fresh
every time a document is loaded.
jQuery Mobile doesn't
re-load the document. It loads "pages" (a foreign concept
for HTML) into a single document that is always retained.
You have to think
differently. It's best, I think to load all of your code in
<head>. That code needs to anticipate what pages *might* be
loaded, and the code should act when/if those pages are loaded.
You can also include JS
on individual pages. You need to put it inside the page div, at
the bottom of the page.