首页 > 解决方案 > 使用 Imask 的可选十进制长度

问题描述

我正在使用 IMask 在我的应用程序中屏蔽百分比输入。默认小数长度应为 2,但用户应该能够编写更具体的小数,直到点后 5 个字符。在大多数情况下,我当前的代码运行良好:

st PERCENTAGE_MASK = {
mask: 'num[000]%',
lazy: false,
blocks: {
    num: {
        mask: Number,
        scale: 2, // digits after point, 0 for integers
        signed: false, // disallow negative
        padFractionalZeros: true, // if true, then pads zeros at end to the length of scale
        normalizeZeros: true, // appends or removes zeros at ends
        min: 0,
        max: 100,
        radix: '.', // fractional delimiter
        mapToRadix: [',', '.'], // symbols to process as radix
    },
},

但是,当用户开始写入 2 个零时,点将被忽略。有人对这种情况有很好的解决方案吗?提前致谢

标签: javascriptmaskpercentageangular-ui-mask

解决方案


推荐阅读