Javascript String检查字母个数

Posted enmmmm

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Javascript String检查字母个数相关的知识,希望对你有一定的参考价值。

1 <script>
2 var txt="ABCDEFGHIJKLMNOPQRSTUVWXYZvshjkdjlksdhbasndhbawnieoqawinsbdvhzohcvikzbncxiouj";
3 var index=0,count=0,position=0;
4 index = txt.indexOf("h",position);
5 document.getElementById("demo").innerhtml=index;
6 while(index!=-1){
7         count++;
8            position = index + 1;
9         index = txt.indexOf("h",position);
10 }
11 document.getElementById("demo").innerHTML=count;
12 </script>

摘自https://www.cnblogs.com/ghostang/

以上是关于Javascript String检查字母个数的主要内容,如果未能解决你的问题,请参考以下文章