[Html]
<! Doctype html>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gbk">
<Script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ("Input: button"). click (function (){
Count ();
});
});
Function count (){
Var str = $ ("input: text"). val (); // get the value in the input box
Var maxlength = 0; // defines the maximum number of times
// Loop: obtain the first character of the string each time, and replace it with null to obtain the number of characters. Until the string is empty
While (str! = ""){
Var oldstr = str; // define a new variable for the string
Letter = str. substr (); // use the substr method to obtain the first character of the string.
Var str = str. replace (new RegExp (letter, "g"), ""); // use a regular expression to replace "the same character as the first character" in the string with null
// "Oldstr. length-str. length" indicates the number of the current character and determines whether it is greater than the number of the previous character.
If (oldstr. length-str. length> maxlength ){
Maxlength = oldstr. length-str. length; // assign the current number of characters to the variable maxlength
$ ("Span"). text (letter );
$ ("Em"). text (maxlength );
};
};
};
</Script>
<Style type = "text/css">
Span, em {color: #933; padding: 0 5px ;}
. Text {width: 500px ;}
</Style>
<Title> find the most frequently occurring character in a string </title>
</Head>
<Body>
<H2> output a string of the most frequently occurring characters! </H2>
<Input class = "text" type = "text" value = ""/>
<Input type = "button" value = "Search"/>
<P> "<span> search... </span>" appears most times. <em> computing... </em> appears in total. </P>
</Body>
</Html>
<! Doctype html>
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gbk">
<Script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type = "text/javascript"> </script>
<Script type = "text/javascript">
$ (Function (){
$ ("Input: button"). click (function (){
Count ();
});
});
Function count (){
Var str = $ ("input: text"). val (); // get the value in the input box
Var maxlength = 0; // defines the maximum number of times
// Loop: obtain the first character of the string each time, and replace it with null to obtain the number of characters. Until the string is empty
While (str! = ""){
Var oldstr = str; // define a new variable for the string
Letter = str. substr (); // use the substr method to obtain the first character of the string.
Var str = str. replace (new RegExp (letter, "g"), ""); // use a regular expression to replace "the same character as the first character" in the string with null
// "Oldstr. length-str. length" indicates the number of the current character and determines whether it is greater than the number of the previous character.
If (oldstr. length-str. length> maxlength ){
Maxlength = oldstr. length-str. length; // assign the current number of characters to the variable maxlength
$ ("Span"). text (letter );
$ ("Em"). text (maxlength );
};
};
};
</Script>
<Style type = "text/css">
Span, em {color: #933; padding: 0 5px ;}
. Text {width: 500px ;}
</Style>
<Title> find the most frequently occurring character in a string </title>
</Head>
<Body>
<H2> output a string of the most frequently occurring characters! </H2>
<Input class = "text" type = "text" value = ""/>
<Input type = "button" value = "Search"/>
<P> "<span> search... </span>" appears most times. <em> computing... </em> appears in total. </P>
</Body>
</Html>