indexOf()怎么寻找第几个的位置?
indexOf()怎么寻找第几个的位置?
indexOf()怎么寻找第几个的位置?
2017-04-02
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>string对象 </title>
<script type="text/javascript">
var str = "Hello World!ol ol ol ol ol ol ol";
var con= 0;
for(i=1;i<str.length;i++)
{
con= str.indexOf("o",con);
if (con!=-1)
{con+=1;}
else
{break;};
if(i==3)
{document.write("第"+i+"个o的位置是"+con+"<br>");
break;}
else{}
}
</script>
</head>
<body>
</body>
</html>
举报