2013-02-06 14 views
3

我試圖檢查Android版本是否小於4與phonegap。檢查android版本是否小於4與phonegap?

我正在使用這個版本。

var deviceOS = device.platform; //fetch the device operating system 
    var deviceOSVersion = device.version; //fetch the device OS version 
      alert("Device OS: " + deviceOS); 
      alert("Device OS Version: " + deviceOSVersion); 

並試圖檢查版本是否小於4,但它不工作?

if (deviceOSVersion < 4) { 
    alert("android less than 4"); 
} 

我測試了一些東西,但沒有運氣。
任何輸入讚賞謝謝。

更新: 我試圖設置最後一個代碼「useAnimations:animationen」爲假如果它是和Android小於4,如果它是iPhone的「animationen」應該是true。 但在iPhone上,它是錯誤的下面的代碼?

var int = 0; 
    var animationen=''; 

    function onBodyLoad() 
     {   
     document.addEventListener("deviceready", onDeviceReady, false); 
     } 

     function onDeviceReady() 
     { 
    getDeviceProperty(); 
     } 

    function getDeviceProperty(){ 
    var deviceOS = device.platform; //fetch the device operating system 
    var deviceOSVersion = device.version; //fetch the device OS version 
      alert("Device OS: " + deviceOS); 
      alert("Device OS Version: " + deviceOSVersion); 


if (deviceOS.indexOf('Android') >= 0) { 
alert("its an android"); 
int = parseInt(deviceOSVersion); 
if(int<4){ 
alert("animation false"); 
animationen=false; 
} 
alert("apptype = android"); 
} 
else 
{ 
alert("apptype = iphone"); 
animationen=true; 
}      
} 


var jQT = new $.jQTouch({ 
useAnimations: animationen 
}); 

回答

4

您需要parseInt函數使用收到的值,

if(parseInt(deviceOSVersion, 10) < 4) 
{ 
    // your code 
} 

希望幫助

+0

它有助於感謝;) – numediaweb

+0

其實你可以簡單地做一個字符串比較:'deviceOSVersion <「4」' – user276648

1
var int = 0; 
....// your code here 
int = parseInt(deviceOSVersion); 
if(int<4){ 
//do something 
} 

我檢查了它的工作。

+0

謝謝你們。它有效,但我仍然有問題。我會更新我的代碼並解釋。 –