有没有办法让用户只输入三个字符?例如,我只想在输入文本字段中允许 3
、6
或 9
。
最佳答案
这里有一个使用 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 = '';
}
});
关于javascript - 让用户在输入文本字段中仅键入三个不同的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6131100/