字符串值检索中,检索相同字符第n个出现的位置?
indexOf()
indexOf()
2016-09-26
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>string对象 </title> <script type="text/javascript"> var mystr="Hello World!Hello World!Hello World!" ; for(i=1;i<+mystr.length;i++) { var o_length=mystr.indexOf("o",i); if(o_length!=mystr.indexOf("o",i-1)) { if(o_length!=-1){document.write(o_length+"<br/>")} } } </script> </head> <body> </body> </html>
举报