从右到左蒙版输入jQuery [英] Right to left mask input with jQuery
本文介绍了从右到左蒙版输入jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在jQuery中输入以下掩码:
I have the following mask input in jQuery:
$("#id_Account").mask("9999",{placeholder:"0"})
此文本框的当前行为是使用零作为占位符以键入我只需要的数字,然后在键入enter后用0填充其余部分. 但是我想在输入后在左侧而不是在右侧用0填充.
The current behaviour of this textbox is to have zeros as placeholder to type the numbers that i just need and then fill the rest with 0's after typing enter. But I would like to fill the with 0's at left side, not at right side after typing.
例如,我在texbox中有"0000"(或只是空白),然后键入"12",然后文本框显示此值:"1200",但我真正想要的是此值:"0012" "
For example, I have in the texbox "0000" (or just blank), then I type "12", then the textbox is showing this value: "1200", but that i really want is this value: "0012"
推荐答案
我通过以下方式实现了自己:
I implemented myself with something like this:
<input name="myaccount1" type="text" style="text-align:right" onchange="mask_account(this)">
这是功能:
function mask_account(field_account){
var qty_chars = field_account.value.length;
var zeros = ''
for (i=0; i < 4 - qty_chars; i++ ){
zeros= zeros + '0';
}
var new_value = zeros + field_account.value;
field_account.value = new_value;
}
这篇关于从右到左蒙版输入jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文