如何将一个值添加到"0001"。当我给这个数字加一个值时,结果只显示2。我怎么能得到0002?
我使用的是这个代码:
var pcode = $('#productcode').val(); // Now the pcode value is 0001
var num= parseInt(pcode) + 1;
But the result shows only 2
添加..后只需调用此函数。。
function z4(n) {
var sign = +n < 0;
n = ''+n;
while(n.length<4) n = '0' + n;
return (sign ? '-' : '' ) + n;
}
z4(2); // 0002