开发者

Jquery mobile, cannot get it to change page using $.mobile.changePage

I am using the following code to programmatically change the page in my app with phonegap:

$('#selection').change(function() {
    alert($(this).val());
    $.mobile.changePage($("#about"), "slideup");
});

When the user changes the selection, the alert fires off and in theory should send them to the following jquery object.

    <div data-role="page" id="about" data-id="about">  
    <div data-role="header" data-position="fixed" data-nobackbtn=”false”><h1>About Us</h1></div>
    <div data-role="content">
        <p>Information about the company</p>
    </div> 
    </div>  

The object works fine with normal linking

<span><a href="#about" data-transition="fade">About Us</a></span>

But I cannot get it to load programmtically in the browser or within phone gap.

Any ideas? I must have looked up the API a million times.

Full html is as follows:

<!DOCTYPE HTML>
<html>
<head>
<title>Header</title>
<script type="text/javascript" charset="utf-8" src="js/phonegap-0.9.3.js"></script>


<link rel="stylesheet" href="css/jquery.mobile-1.0a1.min.css" /> 
<script src="js/jquery-1.4.3.min.js"></script> 
<script src="js/jquery.mobile-1.0a1.min.js"></script>
<script src="js/mycustomjs.js"></script>

<script type="text/javascript">


// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {

        function reachableCallback(reachability) {
            // There is no consistency on the format of reachability
            var networkState = reachability.code || reachability;

            var states = {};
            states[NetworkStatus.NOT_REACHABLE]                      = 'No network connection';
            states[NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK] =开发者_如何学Python 'Carrier data connection';
            states[NetworkStatus.REACHABLE_VIA_WIFI_NETWORK]         = 'WiFi connection';

            alert('Connection type: ' + states[networkState]);
        }

        navigator.network.isReachable('phonegap.com', reachableCallback);


}

</script>  

</head>
<body>




<!-------------- INDEX PAGE ------------------------------------>
<div data-role="page" id="home">  
    <div data-role="header" data-position="fixed" data-nobackbtn=”false”>
            <h1 header</h1>
    </div>

    <div data-role="content">
    <p>Thank you for downloading our app</p>
        <div data-role="fieldcontain">
                <label for="selection" class="select">Please select an industry</label>
                <select name="selection" id="selection">
                        <option value="choice1">choice1</option>
                </select>
        </div>
    </div> 
</div>  

<!-------------- ABOUT PAGE ------------------------------------>
<div data-role="page" id="about" data-id="about">  
    <div data-role="header" data-position="fixed" data-nobackbtn=”false”>
            <h1>About Us</h1>
    </div>

    <div data-role="content">
        <p>Information about the company</p>
    </div> 

 </div>  

</body>
</html>


You are using jquery-mobile 1.0 alpha 1, which it looks like had a significantly different API. changePage for example, had the following signature [1]:

function changePage( from, to, transition, back )

Which I assume (didn't try, though) you could use as

$.mobile.changePage($('#home'), $('#about'), 'slide-up', false);

Although I think that it would be better to upgrade to 1.0 beta2 (latest release) unless there is an incompatibility with phonegap that would keep you from using it (as far as I know, there isn't any). If you upgrade, your above code should work well.

.[1]: https://github.com/jquery/jquery-mobile/blob/1.0a1/js/jquery.mobile.js#L159


I think you need the options to be an object rather than string.

So perhaps try your code with:

$.mobile.changePage($("#about"), { transition: "slideup"});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜