jquery - 使用 jquery 检查 android 版本是否 < 4.1

标签 jquery

我正在尝试为不同的android版本应用功能。我的代码是:

var deviceAgent = navigator.userAgent.toLowerCase();
    var agentID = deviceAgent.match(/(Android)/i);
    if (agentID) {
        var androidversion = parseFloat(agentID.slice(agentID.indexOf("Android")+8));
       if (androidversion < 4.1)
        {
           alert(agentID + androidversion + 'I am older than JB');
             newsblocks(); 
        } else {
           alert(agentID + androidversion + 'I am JB and up');
        }
        } else {
      alert('I am not android');
    }

但由于某些原因,这段代码不起作用,无论 Android 版本如何读取它,它都会显示“我是 JB 及以上”。您能帮我解决这个问题吗?

非常感谢

最佳答案

var agentID = deviceAgent.match(/Android\s+([\d\.]+)/)[1]

示例:http://jsfiddle.net/DZEYk/1/ http://jsfiddle.net/DZEYk/3/

来自here

关于jquery - 使用 jquery 检查 android 版本是否 < 4.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19033920/

相关文章:

javascript - 当一些是字符串而一些是数字时,如何对数组中的项目执行数学运算?

Ruby on Rails 3 上的 jQuery 验证器插件?

jquery - 将字符串数组从 MVC 返回到 jQuery ASP.NET

jquery - 多个 CSS 规则或 jquery

jquery - 使用 jquery 仅显示下一个 <li> 元素

php - 将 JavaScript 事件放置在动态加载的 PHP 表单上

jquery - 页内 anchor 在 Firefox 中不起作用

加载html内容后jquery调用函数

javascript - 即使单击后也更改按钮颜色

javascript - 如何给标记一个 z-index wild-googlemaps