Limit input box can only enter pure digital input
1、onkeyup = "value=value.replace(/[^\d]/g,'')"
Use onkeyup event, there are bug, that is, in the Chinese input method status, just press Enter after input Chinese characters, will directly enter the letters
2、
onchange = "value=value.replace(/[^\d]/g,'')"
Use onchange event, after typing in, lose focus when only input will get results, not just respond when input
3、
oninput = "value=value.replace(/[^\d]/g,'')"
Use oninput event, the perfect solution to these two problems, the test had no other problems.
Code Example <! DOCTYPE HTML > < HTML lang = "EN" > < head > < Meta charset = "UTF-. 8" /> < title > INPUT </ title > </ head > < body > only purely digital input input box: < iNPUT type = "text" name = "" onInput = "value = value.replace (/ [^ \ D] / G, '')" > </ body > </ HTML >