2014-03-05 26 views
0

我有一個文本框,我需要使用onkeypress(限制特殊字符)來驗證我的文本框。它在Chrome中正常工作。在Mozilla Firefox中它不會觸發(Tab Button)。是否有任何事件要添加到我的代碼中。在Javascript onkeypress事件中,Tab按鈕不會觸發(在Mozilla Firefox中)

我的代碼:

function alpha(e) { 
    var k; 
    document.all ? k = e.keyCode : k = e.which; 
    return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 9); //k=9(keycode for tab) 
} 
+1

你確定它不是9嗎?它在我的Windows 7電腦上。 – putvande

+1

像putvande說,標籤的keycode是9 http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes – Anton

+0

你可以發佈的代碼是你的事件關聯事件處理程序? – dreamweiver

回答

1

試驗驗證碼

function alpha(e) { 
    var code = e.keyCode || e.which; 
    if(code == 9) { //Tab keycode 
     //Do something 
    } 
} 
1

這可以幫助你。

function alpha(e){ 
    var k = e.charCode ? e.charCode : e.keyCode; 
    return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 9); //k=9(keycode for tab) 
} 
相關問題