This code shows how to generate a table of contents for the content in Div#content, as well as parsing the H-series tags. Of course, there were some people who realized it earlier.
? 1. Code [HTML] Code
<title> Testing </title>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<script type= "Text/javascript" src= ". /lib/js/jquery-1.7.1.min.js "></script>
<body>
<script type= "Text/javascript" >
$ (document). Ready (function () {
index01
$ ("#index01"). Text ($ ("#content"). html ());
index02
x = $ ("H1,h2"). ToArray ();
c = "";
for (i = 0; i < x.length; i++)
{
c = C + x[i].innerhtml + "<br/>";
}
$ ("#index02"). HTML (x + "<br/>" + C);
index03
x = $ ("h1,h2");
c = "";
X.each (function () {
c = C + $ (this). The text () + "" "+ $ (This). Prop (' tagName ') +" <br/> "; The difference between prop () and attr ()
}); http://www.huiyi8.com/hunsha/lifu/?
$ ("#index03"). HTML (c);
index04
Generate anchor
x = $ ("h1,h2");
n = 0;
c = "";
X.each (function () {
$ (this). Before ("<a name= ' anchor" + n + "' ></a>");
if ($ (this). Prop (' tagName ') = = "H1")//Not available "H1"
{Wedding Dress Appreciation
c=c+ "<a href= ' #anchor" +n+ "' class= ' anchor-h1 ' > ' +$ (This). Text () +" </a><br/> ";
}
else {
c=c+ "<a href= ' #anchor" +n+ "' class= ' anchor-h2 ' > ' +$ (This). Text () +" </a><br/> ";
}
n = n + 1;
});
$ ("#index04"). HTML (c);
});
</script>
<div id= "index01" ></div><div id= "index02" ></div><div id= "index03" ></div><div id= "index04" ></div><div id= "Content" >
<p> Hello </p>
</div>
</body>
?
2.
[Image]01.jpg
Use jquery to generate catalogs for blogs