[英]How to fix this currency mask for text input?
嘿伙計們,我想屏蔽一些這樣的數字:
001 -> 0,01 || 10000 -> 100,00 || 10012300 -> 100.123,00 等等...
但我的代碼只是把“,”
$(document).ready(function () {
var mask = {
money: function () {
var el = this
, exec = function (v) {
v = v.replace(/\D/g, "");
v = new String(Number(v));
var len = v.length;
if (len > 2)
v = v.replace(/(\d{2})$/, ',$1');
else if (2 == len)
v = v.replace(/(\d)/, "0,$1");
else if (1 == len) {
v = v.replace(/(\d)/, "0,0$1");
}
return v;
};
setTimeout(function () {
el.value = exec(el.value);
}, 1);
}
}
$(function () {
$('#money').bind('keypress', mask.money);
$('#money').bind('keyup', mask.money);
});
});
你能幫忙嗎? 如果可能的話,我想輸入“R$”,如下所示:
“R$ 1.123.254,00”。
非常感謝。
你去吧。
html
<label for="currencyMask"> R$</label>
<form action="#">
<input id="currencyMask" name="currencyMask" value="" required/>
</form>
javascript
$('input[name=currencyMask]').mask('#.##0,00', {reverse: true, maxlength: false});
筆記。 您需要包含 jquery。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.