<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//假定字符串的每节数都在5位以下
function toNum(a) {
var a = a.toString();
//也可以这样写 var c=a.split(/\./);
var c = a.split('.');
var num_place = ["", "0", "00", "000", "0000"], r = num_place.reverse();
for (var i = 0; i < c.length; i++) {
var len = c[i].length;
c[i] = r[len] + c[i];
}
var res = c.join('');
return res;
}
function cpr_version(a, b) {
var _a = toNum(a), _b = toNum(b);
if (_a == _b) console.log("版本号相同!版本号为:" + a);
if (_a > _b) console.log("版本号" + a + "是新版本!");
if (_a < _b) console.log("版本号" + b + "是新版本!");
}
var a = "2.2.3"; b = "2.1.15";
cpr_version(a, b);
</script>
</body>
</html>
版权声明:本文为Time_Flies_lei原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。