ngp*_*und 6 jquery jquery-ui jquery-selectors
我有一个输入框,限制为16个数字.我想为美学做的是每4个数字留一个间隙.
例如.当一个人进入
1234567891234567
它看起来应该是这样的
1234 5678 9123 4567
如何在JQuery Key Up中实现这一点?
您可以使用模函数:
$("input").keyup(function(){
var $this = $(this);
if ((($this.val().length+1) % 5)==0){
$this.val($this.val() + " ");
}
});
Run Code Online (Sandbox Code Playgroud)
然而它有点问题,但对你来说可能是一个很好的起点。
正如其他用户所提到的,这对可用性不利,最好使用 4 个文本框(如果长度始终为 16)并使用如下所示的内容:
$("input").keyup(function(){
var $this = $(this);
if ($this.val().length>=4){
$this.next().focus();
}
});
Run Code Online (Sandbox Code Playgroud)
再说一次,可能有点错误,我只是指出不同的方法。
| 归档时间: |
|
| 查看次数: |
6229 次 |
| 最近记录: |