سؤال

I'm using jQuery mobile multipage template and I wanna open the second page programmatically. Here's my sample html:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<meta charset="utf-8" />

</head>
<body>
    <!--===========This is the first page==========-->
    <div data-role="page" id="page1">
        <div data-role="header" data-theme="e">
            <h1>Dialog</h1>
        </div>
        <div data-role="content" data-theme="a">    
            <h1>This is page One</h1>
        </div>
        <div data-role="footer">
            <h4>Page Footer</h4>
        </div>
    </div>

    <!--========================================================-->

    <!--===========This is the second page==========-->
    <div data-role="page" id="page2">
        <div data-role="header" data-theme="e">
            <h1>Dialog</h1>
        </div>
        <div data-role="content" data-theme="a">    
            <h1>This is page Two</h1>
            <
        </div>
        <div data-role="footer">
            <h4>Page Footer</h4>
        </div>
    </div>
    <script>
        jQuery.mobile.changePage($("#page2"));
    </script>
</body>
</html>

Everything seems ok but when I open this page, I get the following error in firebug:

TypeError: u is undefined

I appreciate any comment

هل كانت مفيدة؟

المحلول

Enclose your jquery code in the document.ready() handler:

$(document).ready(function() {
   jQuery.mobile.changePage($("#page2"));
});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top