HTML部分:
<p id="zql">start,stop,speed,start,speed ,velocicty,start</p>
<button onclick="fun()">Try it</button>
<p id="demo1"></p>
<script src="./index.js"></script>
JS部分:
function fun(){
var str = document.getElementById("zql").innerHTML;
var num=0;
var a=str.indexOf("start");
while(a!==-1){
a=str.indexOf("start",a+1);
num++;
}
document.getElementById("demo1").innerHTML = num;
}