This method cannot test the characters used by regular expressions, such as $ ^ .? \
Http://blog.csdn.net/qmzmxfy/article/details/7431488
[HTML] View plaincopyprint?
- <! 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 (){
-
- VaRStr= $ ("Input: Text"). Val (); // obtain the value in the input box
-
- VaRMaxlength=0; // Define 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! = ""){
- VaROldstr=Str; // Define new variables for strings
-
- Letter=Str. Substr (); // use the substr method to obtain the first character of the string.
-
- VaRStr=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 characters in the 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>Searching...</Span>", A total<Em>Computing...</Em>Times.</P>
-
- </Body>
- HTML >