2013-11-22 221 views
0

我使用此代碼只有數字輸入但^ char可以輸入嗎?我該如何修復?僅限HTML輸入數字輸入除^

<input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57'></input> 
+1

看看這個:http://stackoverflow.com/questions/20115337/limiting-number-value-in-an-input -tag-with-javascript/20115673#20115673 – Andrew

+0

你的代碼實際上工作正常。你使用過一些非英文輸入法嗎? –

回答

1
<input type="text" onkeypress='return(event.charCode >= 48 && event.charCode <= 57) || (event.charCode==94) '></input> 

這將解決你的目的

function validateInput(evt) 
{ 
    if ((evt.charCode >= 48 && evt.charCode <= 57) || (evt.charCode==94)) 
     return true; 
    else 
     return false; 
} 

<input type="text" onkeypress='return validateInput(event)'></input> 
+0

@sugar,如果你認爲答案有幫助,不要忘記標記爲正確。 –

+0

它沒有工作 – sugur

+0

讓我做一個小提琴,它適用於我的結局。 –