jQuery-Inputmask插件 [英] jQuery - Inputmask plugin
本文介绍了jQuery-Inputmask插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hei
让任何人都知道jquery中的输入掩码例如,一个字段必须包含三个字母,后跟4个数字. cda1234.如果有人在该字段中写了不适合的内容,则必须连续删除.
Have anyone idea of input mask in jquery For example a field must have three letters followed by 4 numbers. cda1234. If one writes something in the field that does not fit with this must be removed continuously.
推荐答案
快速制作示例,请参见: http ://jsfiddle.net/g8KSg/2/
Cooked an fast example up, see: http://jsfiddle.net/g8KSg/2/
检查前三个字符的非整数,然后仅接受整数.
Checks for non integers for the first 3 characters, and then only accept integers.
可以使用正则表达式进行更明智的选择,但这应该是一个起点:)
Could proberbly be made wiser with regex, but this should give a starting point :)
$('input').keyup(function(e){
var value = $(this).val();
if(value.length <= 3) {
char = value.substring(value.length - 1);
if(!(isNaN(char))) {
var newval = value.substring(0, value.length - 1);
$(this).val(newval);
}
}
if(value.length > 3) {
char = value.substring(value.length - 1);
if(isNaN(char)) {
var newval = value.substring(0, value.length - 1);
$(this).val(newval);
}
}
});
这篇关于jQuery-Inputmask插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文