无法为变量赋值

时间:2016-06-02 18:55:46

标签: javascript

其他if中的代理和其他变量if(linux)语句显示为undefined。此代码适用于除linux之外的所有其他操作系统。但是我可以在控制台中分配值。

function detectoperatingsystem()
 {
    var agent = navigator.userAgent;
    if(/Windows NT (\d+\.\d)/i.test(agent))
    {
        self.osType = "windows";
        self.osTypeDisplay = "Windows";
        self.osVersion = (RegExp.$1).toString();
        configureWindowsVersionDisplay(agent);
    }
    else if(/iP(?:(?:hone)|(?:ad))/i.test(agent))
    {
        self.osType = "iPhone";
        self.osTypeDisplay = "IOS";
        self.isIOS = true;
        configureIOSVersionAndDisplay(agent);
    }
    else if (/Android (\d+\.\d)/i.test(agent)) {
        if (agent.indexOf("Mobile") !== -1)
        {
            self.osType = "AndroidPhone";
            self.osTypeDisplay = "AndroidPhone";
        }
        else
        {
            self.osType = "Android";
            self.osTypeDisplay = "Android";
        }
        self.isAndroid = true;
        self.osVersion = self.osVersionDisplay = RegExp.$1;
    }
    else if(/linux/i.test(agent))
    {
        self.osType = "Linux";
        self.osTypeDisplay = "Linux";
        self.osVersion = 1;
        self.osVersionDisplay = "";
    }
    else
    {
        self.osType = "Unknown";
        self.osVersion = "Unknown";
    }
}

0 个答案:

没有答案