第八周2

<!DOCTYPE html>
<html>
<head>
 <title>aa</title>

<meta charset="utf-8">
</head>
<body>
<button onclick="myFunction()">点我可查看这一串"start,start,end,person,people,velocity,start"字符中"start"字符出现的次数</button>
<p id="demo"></p>
<script type="text/javascript">
 function myFunction(){
 var str = "start,start,end,person,people,velocity,start";
 var count=0;
 var index=0;
 var key="start";
 while((index = str.indexOf(key,index))!= -1){
  index += key.length;
  count = count+1;
 }
 document.getElementById("demo").innerHTML = count;
}
</script>
</body>
</html>

参考至《不一样的少年》

posted @ 2018-10-26 15:58  似水流年掩盖不了难过  阅读(69)  评论(0编辑  收藏  举报