functiongetTheNum(){var str = document.getElementById('str').value;//单词、空格、数组、其他的数量var word =0;var space =0;var num =0;var other =0;for(var i =0; i < str.length; i++){//通过检测该元素的ASCII码来判断if((str[i].charCodeAt()>=65&& str[i].charCodeAt()<=90)||(str[i].charCodeAt()>=97&& str[i].charCodeAt()<=122)){
word++;}elseif(str[i].charCodeAt()>=48&& str[i].charCodeAt()<=57){
num++;}elseif(str[i].charCodeAt()==32){
space++;}else{
other++;}}
console.log('字符:'+ word +'空格:'+ space +'数字:'+ num +'其他:'+ other);}