验证数字并补位

function verPCBValue(dom) {
            let value = dom.val();
            let num = isNaN(parseInt(value)) ? 0 : parseInt(value);
            if (num > 255)
                num = 255;
            if (num < 0)
                num = 0;
            dom.val(padleft(2, num));
        }
function padleft(len, data) {
            while (data.toString().length < len) {

                data = '0' + data;
            }
            return data;

        }

 

posted @ 2022-08-03 10:15  奇迹之耀  阅读(15)  评论(0编辑  收藏  举报