Jquery输入掩码插件

时间:2017-06-29 09:15:07

标签: jquery html

如何填充面具后的最后两位数字?示例:XXXX99
所以,当我输入第一个数字应该是1XXX99



var autoPopulateNo = "\\9\\9"  //how to put this after the mask? example XXXX99

$("#number").inputmask({
"mask": "9999" + autoPopulateNo,
clearMaskOnLostFocus: false,
placeholder:"X",

});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/jquery.inputmask.bundle.js"></script>
<form action="">  
  <div>
    <label for="number">Mask</label>
    <input id="number" type="text"/>
  </div>
</form>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

事情很简单。你只需用掩码附加你的变量。

var autoPopulateNo = 56  
$("#number").inputmask({
"mask": "9999"+autoPopulateNo,
clearMaskOnLostFocus: false,
placeholder:"X",

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/jquery.inputmask.bundle.js"></script>
<form action="">  
  <div>
    <label for="number">Mask</label>
    <input id="number" type="text"/>
  </div>
</form>