2017-06-29 148 views
0

如何填充掩碼後的最後兩位數字?例如:XXXX99
所以,當我在第一個數字鍵應該是1XXX99
jquery輸入掩碼插件

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>

+3

歡迎回來,https://stackoverflow.com/questions/44818443/placeholder-and-value-present-at-the-same-time/44818561#44818561 – TripleDeal

+0

怎麼樣,如果最後兩位數字是99而不是56? – Rick

回答

1

這種事情是這樣simple.You只是追加您的變量與面具。

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>

+0

你可以試試嗎? var autoPopulateNo = 99 – Rick

+0

我會檢查並告訴。 – vishal

+0

剛剛解決,我會更新我的答案 – Rick