Frenlee

JS判断App版本号

使用JS来判断App的版本号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// oprate 比较操作符
var versionCmp = function(nowVersion, version, operate) {
version = version.replace(/[a-zA-Z_]/gi, '')
nowVersion = nowVersion ? nowVersion[0].replace(/[a-zA-Z_]/gi, '') : '';
var versionArr = version.split(".");
versionArr && versionArr.forEach(function(v,k){
versionArr[k] = ("000"+v).substr(-3)
});
version = versionArr.join("");
var nowVersionArr = nowVersion.split(".");
nowVersionArr && nowVersionArr.forEach(function(v,k){
nowVersionArr[k] = ("000"+v).substr(-3)
});
nowVersion = nowVersionArr.join("");
if (!operate) {
operate = '==';
}
return eval(nowVersion+operate+version)
}


// versionCmp("1.2.0", "1.3.0", "<")