<script type="text/javascript">
var mystr="Hello World!ok?"
?
</script>
<script type="text/javascript">
var mystr="Hello World!ok?"
var substring = "o";
document.write(mystr.indexOf(substring, 0));
</script>
<!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>");
}
else{}
}
</script>
</head>
<body>
</body>
</html>
document.write(mystr.indexOf("o",mystr.indexOf("o")+2));
做出来了,但可能太繁琐了!
<script type="text/javascript">
var mystr="Hello World!ok?"
var a=mystr.indexOf("o",mystr.indexOf("o")+1)
document.write(mystr.indexOf("o",a+1));
</script>
不对啊,这样是写是打印出第一“o"所在的位置了
<script type="text/javascript">
var mystr="Hello World!ok?"
var substring = "o";
document.write(mystr.indexOf(substring, 0));
</script>