代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <script type="text/javascript"> var arr = new Array("America","Greece","Britain","Canada","China","Egypt"); var count = 0; for(var i in arr){ document.write(arr[i]+"<br/>"); if(arr[i].indexOf("a")!=-1 || arr[i].indexOf("A") !=-1){ count++; } } document.write("共有"+count+"个字符串中包含a或A。"); </script> </body> </html>
如果程序出现错误,在编译器中是不显示的,这里我们使用谷歌浏览器,检查元素后,点击"Sources",并可以进行断点调试等操作。