让用户在输入文本字段中只键入三个不同的字符

Biz*_*oss 6 html javascript

有没有办法让用户只键入三个字符?例如,我只想允许3,69在输入文本字段.

Thi*_*ter 4

这是使用 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 = '';   
    }
});
Run Code Online (Sandbox Code Playgroud)