<script>ide
// alert( detectNum('123456') );spa
var aInp = document.getElementsByTagName('input');blog
aInp[1].onclick = function () {ip
var val = aInp[0].value;get
if ( detectNum(val) ) {input
alert( '恭喜,'+ val +'全是數字' );it
} else {io
alert('輸入有誤');function
}class
};
function detectNum ( str ) {
var n = 0;
for ( var i=0; i<str.length; i++ ) {
n = str.charCodeAt(i);
if ( n<48 || n>57 )return false;
}
return true;
}
</script>