我使用此代碼只有數字輸入但^ char可以輸入嗎?我該如何修復?僅限HTML輸入數字輸入除^
<input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57'></input>
我使用此代碼只有數字輸入但^ char可以輸入嗎?我該如何修復?僅限HTML輸入數字輸入除^
<input type="text" onkeypress='return event.charCode >= 48 && event.charCode <= 57'></input>
<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>
看看這個:http://stackoverflow.com/questions/20115337/limiting-number-value-in-an-input -tag-with-javascript/20115673#20115673 – Andrew
你的代碼實際上工作正常。你使用過一些非英文輸入法嗎? –