让用户在输入文本字段中只键入三个不同的字符 [英] Let user type only three different characters in an input text field
本文介绍了让用户在输入文本字段中只键入三个不同的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法让用户只输入三个字符?例如,我想只允许 3
, 6
或 9
在输入文本字段中。
Is there a way to let the user type only three characters? For example, I want to only allow 3
, 6
or 9
in an input text field.
推荐答案
以下是使用jQuery的方法: http://jsfiddle.net/ThiefMaster/UZJn2/
Here's a way to do it using jQuery: http://jsfiddle.net/ThiefMaster/UZJn2/
<input type="text" maxlength="1" class="only369" />
$('.only369').keyup(function(e) {
if(this.value != '3' && this.value != '6' && this.value != '9') {
this.value = '';
}
});
这篇关于让用户在输入文本字段中只键入三个不同的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文