输入掩码数字,带有两个小数位

时间:2015-11-27 03:49:22

标签: javascript jquery input-mask jquery-inputmask

我尝试使用名为"输入掩码"的伟大插件将我的正常输入字段转换为带有两个小数位的数字输入。令人敬畏的" RobinHerbots",下面的片段就是我尝试的但很遗憾,不幸的是它不起作用,任何想法,请帮忙吗?



$(document).ready(function(){
  $('.decimal').inputmask('decimal', { rightAlign: false, digits: 2, placeholder: "0" });
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/RobinHerbots/jquery.inputmask/3.x/dist/jquery.inputmask.bundle.js"></script>

<input type="text" class="decimal form-control" />
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

$('.decimal').inputmask({ mask: "99.99"}) // As you requested

OR

$('.decimal').inputmask({ mask: "99.9{2}"}) //Same as the first one, {2} mean preceding char count MUST be 2

OR

$('.decimal').inputmask({ mask: "(99)|(99.9{1,2})"}) //We use optional here so user can enter 99 or 99.9 or 99.99

答案 1 :(得分:0)

试试这个

https://jsfiddle.net/Ln375fmz/

$('.decimal').inputmask({
            mask: "9{0,20}Z9{2}",
            definitions: {
                "Z": {
                    validator: "[.]",
                }
            },
            clearIncomplete: true,
            autoUnmask: true,
            placeholder: "",
        });
<input type="text" id="money">