In the past, csdn blogs had no counting function, so they were always using others' counters, but this was not accurate. now the csdn blog has the counter function, so I made a counter using JavaScript + Div.
Basic Principles: The getelementsbytagname function retrieves the number accessed on the page and converts it to an image.
Study the HTML code
<H1> blog Statistics <Ul class = "list">
<Li class = "listitem"> original-75 </LI>
<Li class = "listitem"> translation-0 </LI>
<Li class = "listitem"> posting-5 </LI>
<Li class = "listitem"> click-351278 </LI>
<Li class = "listitem"> comment-891 </LI>
<Li class = "listitem"> trackbacks-41 </LI>
</Ul>
I use the Li label here. You may have different labels, but the principles are the same.
Add a div to display the counter.
<P> <B> access statistics </B> </P> <Div id = counter> </div>
JavaScript code
<Script language = JavaScript>
VaR OBJ = Document. getelementsbytagname ('lil ');
VaR CNT, I;
VaR STR, html = '';
For (CNT = 0; CNT <obj. length; CNT ++)
{
STR = OBJ [CNT]. innerhtml;
If (Str. indexof ('click ')! =-1)
{
STR = Str. substr (5 );
Html = "<Table border = '0'> <tr> <TD bgcolor = '#000000'> ";
For (I = 0; I <Str. length; I ++)
If (Str. substr (I, 1)> = '0' & Str. substr (I, 1) <= '9 ')
HTML + = " ";
HTML + = "</TD> </tr> </table> ";
Document. All ['counter']. innerhtml = HTML;
Break;
}
}
</SCRIPT>
This is my counter.
In addition, the above code is for a lighty-style blog, so if your blog is not of this style, it is invalid even if you use this code. At the request of aeonspider, I slightly changed the code and used the following code to select a cogitation blog. You can also implement the counter function.
<P> <B> access statistics </B> </P> <Div id = counter> </div>
<Script language = JavaScript>
VaR OBJ = Document. getelementsbytagname ('td ');
VaR CNT, I;
VaR STR, html = '';
For (CNT = 0; CNT <obj. length; CNT ++)
{
STR = OBJ [CNT]. innerhtml;
If (Str. indexof ('Next click ')! =-1)
{
Pos = Str. indexof ('click ');
Pos-= 1;
Html = "<Table border = '0'> <tr> <TD bgcolor = '#000000'> ";
For (I = Pos; I> 0; I --)
{
If (Str. substr (I, 1)> = '0' & Str. substr (I, 1) <= '9 ')
Html = " "+ HTML;
Else
Break;
}
HTML + = "</TD> </tr> </table> ";
Document. All ['counter']. innerhtml = HTML;
Break;
}
}
</SCRIPT>