indexOf()如何查找第N个
indexOf()如何查找第N个
indexOf()如何查找第N个
2017-03-13
<!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>
举报