简体   繁体   中英

Jquery Mobile - $(document).ready not firing

So I have a listview in which each component wired to an on click function which looks like this:

function launchNewPage() {
    $.mobile.changePage( "newPage.html", { transition: "slide"} );
}

The problem I am encountering has to do with the next page. The page shows up just fine, but none of the resources are loading. When I inspect the page in firebug, none of the necessary JS files are loaded. On top of this, it doesn't seem like the $(document).ready function is ever getting executed. Does anyone have any insight as to what I am doing wrong? Sorry, I am a bit new to JQ... Thanks in advance.

Requested HTML:

<!DOCTYPE html> 
<html>
<head> 
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, maximum-scale=1"> 
    <title></title> 

    <link rel="stylesheet" href="CSS/JqueryMobile.css" />
    <link rel="stylesheet" href="CSS/theme.css" />  
    <link rel="stylesheet" href="CSS/JQM-DatePicker.css" /> 

    <script type="text/javascript" src="JS/jquery-1.6.2.js"></script>
    <script type="text/javascript" src="JS/JqueryMobile.js"></script>       
    <script type="text/javascript" src="JS/JQM-DatePicker.js"></script>

    <script type="text/javascript" src="JS/mockjax.js"></script>    
    <script type="text/javascript" src="JS/soyutils.js"></script>
    <script type="text/javascript" src="JS/fields.js"></script>
    <script type="text/javascript" src="JS/JSDictionaryObject.js"></script>
    <script type="text/javascript" src="JS/AddingForm.js"></script>
</head> 
<body> 
    <div id="page" data-role="page" data-theme="x">
        <div class="ui-body-x" data-role="header" data-position="fixed">
            <h1 class="ui-header-style" style="text-align:left; margin-left:10px;">Add New Record</h1>
            <div data-type="horizontal"  class="ui-btn-right ui-button-group"> 
                <a id="cancelButton" href="http://www.google.com" data-role="link"  data-ajax="false">Cancel</a>
                <a id="submitButton" form="f" class="ui-btn-up-x" onClick="javascript:return submitPressed();"data-role="button" data-icon="" data-ajax="false">Submit</a> 
            </div>              
        </div><!-- /header -->

        <div data-role="content" data-theme="x">

            <form  id="f" src="#"></form>       
        </div><!-- /content -->

    </div><!-- /page -->

</body>

You cannot start the jQuery mobile with $(document).ready() you should started like this:

try to work with this in the first HTML

$("div[data-role*='page']").live('pageshow', function(event, ui) { 
    document.location.href="newPage.html";
});

Geoff, if you are using the Beta 3 version of the JQM framework, read this . It will help shed light on the DOM and $(document).ready(). You may want to consider the "pagecreate" and "pagebeforecreate" events. They are delineated in the doc referenced in the above link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM