Last Update:2017-08-24
Source: Internet
Author: User
Keywords
Web page production
Ajax
javascript
<html>
<head> <title> Test number </title> <script> function Oncheck () { var numvalue=document.getelementbyid ("num"). Value var index=-1 for (Var i=0;i<numvalue.length;i++) { var ch=numvalue.charat (i); if (ch>=0&&ch<=9) { index=-1 }else{ index=1 Break; { } if (index==1) { Alert ("The non-numeric you entered!") Please re-enter "); document.getElementById ("num") value= ""; return; }else{ alert ("Input correct!") The number you enter is: "+numvalue"; } &NBSp; { function onCheck1 () { var Numvalue=document.getelementbyid ("Num1"). Value; if (isNaN (NumValue)) { alert ("Non-digit you entered!") Please re-enter ... "); document.getElementById ("NUM1") value= ""; return; }else{ alert ("Input correct!") The number you enter is: "+numvalue"; { } </script> </head> <body> <h3> test input is a number the first method </h3> <input type= "text" id= "num"/> <input "button" value= "Test 1" onclick= "Oncheck ()"/> <h3> test input is a number the second method </h3> <input type= "text" id= "NUM1" "/> <input type=" button "value="Test 2 "onclick=" OnCheck1 () "/> </body> </html>