JavaScript中统计字符的个数

<pre name="code" class="html"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>统计包含“a”或“A”的字符串的个数</title>
<script type="text/javascript">
var countryList=["America","Greece","Britain","Canada","China","Egypt"];
var count=0;
document.write("在以下字符中:<br/>");
for(var i in countryList){
document.write(countryList[i]+"<br/>");
if(countryList[i].indexOf("a")!=-1||countryList[i].indexOf("A")!=-1)
count++;
}
document.write("共有"+count+"个字符中串包含a或A。");
</script>
</head>


<body>
</body>
</html>


    实现的比较简单,遇到相似的之后举一反三!!!
posted @ 2016-10-25 23:51  穆雄雄  阅读(2717)  评论(0编辑  收藏  举报