数据库字段+1的问题(js实现)

function doAdd(a,b) {
		var str = "";
		var lenA = parseInt(a.length);
		var lenB = parseInt(b.length);

var maxLen ="";
if(lenA > lenB)
{
maxLen=parseInt(lenA)
}
else{
maxLen=parseInt(lenB)
}

var minLen =""; 
if(lenA < lenB){
  minLen=parseInt(lenA)
} else
{minLen=parseInt(lenB)
}

		var strTmp = "";
		for (var i = maxLen - minLen; i > 0; i--) {
			strTmp += "0";
		}
		// 把长度调整到相同
		if (maxLen == lenA) {
			b = strTmp + b;
		} else
			a = strTmp + a;
		var JW = 0;// 进位
		for (var i = maxLen - 1; i >= 0; i--) {
			var tempA = parseInt(a.charAt(i));
			var tempB = parseInt(b.charAt(i));
			var temp;
			if (tempA + tempB + JW >= 10 && i != 0) {
				temp = parseInt(tempA + tempB + JW - 10);
				JW = 1;
			} else {
				temp = parseInt(tempA + tempB + JW);
				JW = 0;
			}
			str = temp + str;
		}

		return str;

	}
假如数据库字段是:000000009
doAdd("
000000009
","1")
结果是:000000010

你可能感兴趣的:(js校验)