日期:2014-05-16  浏览次数:20397 次

一道课题求解
源代码函数缺少一部分,使函数查询输入域的每个字符并计算域中出现多少个字母e(提示:函数缺少的是for 循环)
HTML code

<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>



------解决方案--------------------
JScript code
for(var i=0,len=inputString.length;i<len;i++){
     if(inputString.charAt(i)=='e') count++;
}