日期:2014-05-16 浏览次数:20397 次
<htmL> <html> <head> <title></title> <script type="text/javascript"> function countE(form){ var count = 0; var inputString = form.mainstring.value.toLowerCase(); var msg = "The string has " + count; msg += " instances of the letter e." alert(msg); } </script> </head> <body> <form> Enter any stirng:<input type="text" name="mainstring" size="30"><br/> <input type="button" value="Conut the Es" onclick="countE(this.form)"> </form> </body> </html> </html>
for(var i=0,len=inputString.length;i<len;i++){ if(inputString.charAt(i)=='e') count++; }