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