2011-08-23 88 views
2

我使用下面的代码与PhoneGap的编程方式更改的页面在我的应用程序中切换分页:

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

当用户改变选择,警报发生在理论上应该发送给下面的jquery对象。

<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> 

对象正常工作与正常连接

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

但我不能让它在浏览器或手机间隙内programmtically加载。

任何想法?我一定会查找API一百万次。

完整的HTML如下:

<!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] = '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> 
+0

嗨,该代码为我工作(与jQuery Mobile的1.0b2)。请参阅https://gist.github.com/1164723您可以显示完整的HTML吗? – Zaki

+0

已完成html添加。 – Billie

回答

1

您正在使用jQuery移动1.0阿尔法1,它看起来像有显著不同的API。 changePage例如,有以下特征[1]:

function changePage(from, to, transition, back) 

我假设(没有尝试,虽然)虽然我认为这将是更好的,你可以为

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

使用升级到1.0 beta2(最新版本),除非与phonegap不兼容,否则将无法使用它(据我所知,没有)。如果你升级,你的上面的代码应该运行良好。

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

+0

我已经升级了,而且做到了! ty :) – Billie

1

我认为你需要的选项是一个对象,而不是字符串。

因此,也许尝试你的代码:

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

它对我来说很好。谢谢。 –