{"id":586,"date":"2016-06-11T16:48:24","date_gmt":"2016-06-11T08:48:24","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=586"},"modified":"2016-06-11T16:58:41","modified_gmt":"2016-06-11T08:58:41","slug":"%e8%af%a6%e8%a7%a3%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e5%8d%9a%e6%96%87%e4%b8%ad%e8%87%aa%e5%8a%a8%e7%94%9f%e6%88%90%e6%96%87%e7%ab%a0%e7%9b%ae%e5%bd%95%e7%9a%84%e5%81%9a%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=586","title":{"rendered":"\u8be6\u89e3\u5982\u4f55\u5b9e\u73b0\u535a\u6587\u4e2d\u81ea\u52a8\u751f\u6210\u6587\u7ae0\u76ee\u5f55\u7684\u505a\u6cd5"},"content":{"rendered":"<p>\n\t<span style=\"font-family:comic sans ms,cursive\"><span style=\"font-size:16px\">\u5728CSDN\u5199\u8fc7\u535a\u5ba2\u7684\u4eba\u53ef\u80fd\u4f1a\u4f7f\u7528\u5b83\u63d0\u4f9b\u7684&ldquo;\u6587\u7ae0\u4e2dH1\u5230H6\u6807\u7b7e\u81ea\u52a8\u751f\u6210\u6587\u7ae0\u76ee\u5f55&rdquo;\u8fd9\u4e2a\u529f\u80fd\u3002\u800c\u4e14\u8fd9\u6837\u7684\u6587\u7ae0\u770b\u8d77\u6765\u5f88\u9192\u76ee\uff0c\u80fd\u591f\u5feb\u901f\u7684\u5b9a\u4f4d\u5230\u81ea\u5df1\u60f3\u770b\u7684\u5185\u5bb9\uff0c\u53ef\u4ee5\u8bf4\u662f\u6df1\u53d7\u5e7f\u5927\u535a\u53cb\u7684\u559c\u7231\u3002\u90a3\u4e48\u8fd9\u6837\u53cb\u597d\u7684\u529f\u80fd\u662f\u5982\u4f55\u5b9e\u73b0\u7684\u5462\uff1f\u4e14\u770b\u5c0f\u7f16\u4eca\u5929\u4e3a\u5927\u5bb6\u63ed\u5f00\u5b83\u7684\u795e\u79d8\u9762\u7eb1\u3002<br \/>\n\t\u5148\u770b\u770b\u8fd0\u884c\u6548\u679c\u5427\uff1a<br \/>\n\t<img decoding=\"async\" alt=\"\u535a\u5ba2\u6587\u7ae0\u76ee\u5f55\" src=\"http:\/\/sandbox.runjs.cn\/uploads\/rs\/133\/80kwuubo\/586.png\" \/><br \/>\n\t\u6574\u4f53\u8fd0\u884c\u6548\u679c\u770b\u8d77\u6765\uff0c\u8fd8\u4e0d\u9519\u5427\uff01<a href=\"http:\/\/sandbox.runjs.cn\/show\/sgs5ibkq\" target=\"_blank\">\u70b9\u51fb\u6b64\u5904<\/a>\u67e5\u770b\u8be6\u7ec6\u8fd0\u884c\u6548\u679c<br \/>\n\t\u6211\u5148\u8bf4\u4e0b\u5b9e\u73b0\u601d\u8def<br \/>\n\t<strong><span style=\"color:#000080\">1.\u6574\u4f53\u76ee\u5f55\u4f7f\u7528\u7684\u662fol\u548cli\u6807\u7b7e\u5b9e\u73b0<br \/>\n\t2.\u70b9\u51fb+\u3001-\u5224\u65ad\u662f\u5426\u5c55\u5f00\u548c\u6536\u8d77<br \/>\n\t3.\u4f7f\u7528a\u6807\u7b7e\u5b9e\u73b0\u951a\u70b9\u5b9a\u4f4d<\/span><\/strong><br \/>\n\t\u5168\u90e8\u6e90\u7801<a href=\"http:\/\/runjs.cn\/code\/sgs5ibkq\" target=\"_blank\">\u70b9\u51fb\u6b64\u5904<\/a>\u67e5\u770b<br \/>\n\t\u6211\u4eec\u4eca\u5929\u7684\u91cd\u70b9\u662f\u5982\u4f55\u8ba9\u4f60\u7684\u7f51\u7ad9\u4e5f\u652f\u6301\u8fd9\u6837\u7684\u529f\u80fd\u3002\u505a\u7684\u601d\u8def\u5982\u4e0b\uff1a<br \/>\n\t<u><span style=\"color:#000080\">1.\u67e5\u627e\u6240\u6709\u7684h1,h2,h3,h4,h5,h6\u6807\u7b7e(\u6392\u9664\u6587\u7ae0\u6807\u9898)<br \/>\n\t2.\u6309h1\u5230h6\u7684\u987a\u5e8f\u6dfb\u52a0ol\u548cli\uff0c\u5e76\u62fc\u63a5\u6210html\uff0c\u5177\u4f53\u505a\u6cd5\u5982\u4e0b\uff1a<br \/>\n\t&nbsp; \u6240\u6709\u7684h1\u90fd\u4f5c\u4e3aTree\u76841\u7ea7\u8282\u70b9\uff0ch2\u4f5c\u4e3a\u4e0a\u4e00\u4e2ah1\u7684\u5b50\u8282\u70b9,h3\u4f5c\u4e3a\u4e0a\u4e00\u4e2ah2\u7684\u5b50\u8282\u70b9\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002<br \/>\n\t3.\u7ed9\u5bf9\u5e94\u7684\u8282\u70b9\u6dfb\u52a0\u81ea\u5b9a\u4e49\u7684\u951a\u70b9<br \/>\n\t4.\u70b9\u51fb+\u3001-\u7b26\u53f7\uff0c\u5206\u522b\u6267\u884c\u5c55\u5f00\u548c\u6536\u8d77\u52a8\u4f5c<\/span><\/u><br \/>\n\t\u5168\u90e8\u4ee3\u7801\u5982\u4e0b\uff1a<\/span><\/span>\n<\/p>\n<pre class=\"brush:xml;\">\r\n$(document).ready(function() {\r\n&nbsp;&nbsp; &nbsp;\/\/ \u4e1a\u4f59\u8349\uff1awww.xttblog.com\r\n&nbsp; &nbsp; initCatalog();\r\n});\r\n\r\nfunction initCatalog() {\r\n&nbsp; &nbsp; var hs = $(&#039;#article&#039;).find(&#039;h1,h2,h3,h4,h5,h6&#039;);\r\n&nbsp; &nbsp; if (hs.length &lt; 2)\r\n&nbsp; &nbsp; &nbsp; &nbsp; return;\r\n&nbsp; &nbsp; var html = &#039;&#039;;\r\n&nbsp; &nbsp; html += &#039;&lt;div style=&quot;clear:both&quot;&gt;&lt;\/div&gt;&#039;;\r\n&nbsp; &nbsp; html += &#039;&lt;div class=&quot;xttblog_toc&quot;&gt;&#039;;\r\n&nbsp; &nbsp; html += &#039;&lt;p style=&quot;text-align:right;margin:0;&quot;&gt;&lt;span style=&quot;float:left;&quot;&gt;\u76ee\u5f55&#039;;\r\n&nbsp;&nbsp; &nbsp;html += &#039;&lt;a href=&quot;#&quot; title=&quot;\u7cfb\u7edf\u6839\u636e\u6587\u7ae0\u4e2dH1\u5230H6\u6807\u7b7e\u81ea\u52a8\u751f\u6210\u6587\u7ae0\u76ee\u5f55&quot;&gt;(?)&lt;\/a&gt;&lt;\/span&gt;&#039;;\r\n&nbsp;&nbsp; &nbsp;html += &#039;&lt;a href=&quot;#&quot; onclick=&quot;javascript:return openct(this);&quot; title=&quot;\u5c55\u5f00&quot;&gt;[+]&lt;\/a&gt;&lt;\/p&gt;&#039;;\r\n&nbsp; &nbsp; html += &#039;&lt;ol style=&quot;display:none;margin-left:14px;padding-left:14px;line-height:160%;&quot;&gt;&#039;;\r\n&nbsp; &nbsp; var old_h = 0, ol_cnt = 0;\r\n&nbsp; &nbsp; for (var i = 1; i &lt; hs.length; i++) {\r\n&nbsp; &nbsp; &nbsp; &nbsp; var h_tag = parseInt(hs[i].tagName.substr(1), 10);\r\n&nbsp; &nbsp; &nbsp; &nbsp; if (!old_h)\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; old_h = h_tag;\r\n&nbsp; &nbsp; &nbsp; &nbsp; if (h_tag &gt; old_h) {\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; html += &#039;&lt;ol&gt;&#039;;\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ol_cnt++;\r\n&nbsp; &nbsp; &nbsp; &nbsp; }else if (h_tag &lt; old_h &amp;&amp; ol_cnt &gt; 0) {\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; html += &#039;&lt;\/ol&gt;&#039;;\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ol_cnt--;\r\n&nbsp; &nbsp; &nbsp; &nbsp; }\r\n&nbsp; &nbsp; &nbsp; &nbsp; if (h_tag == 1) {\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while (ol_cnt &gt; 0) {\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; html += &#039;&lt;\/ol&gt;&#039;;\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ol_cnt--;\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }\r\n&nbsp; &nbsp; &nbsp; &nbsp; }\r\n&nbsp; &nbsp; &nbsp; &nbsp; old_h = h_tag;\r\n&nbsp; &nbsp; &nbsp; &nbsp; var tit = hs.eq(i).text().replace(\/^\\d+[.\u3001\\s]+\/g, &#039;&#039;);\r\n&nbsp; &nbsp; &nbsp; &nbsp; tit = tit.replace(\/[^a-zA-Z0-9_\\-\\s\\u4e00-\\u9fa5]+\/g, &#039;&#039;);\r\n\r\n&nbsp; &nbsp; &nbsp; &nbsp; if (tit.length &lt; 100) {\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; html += &#039;&lt;li&gt;&lt;a href=&quot;#t&#039; + i + &#039;&quot;&gt;&#039; + tit + &#039;&lt;\/a&gt;&lt;\/li&gt;&#039;;\r\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hs.eq(i).html(&#039;&lt;a name=&quot;t&#039; + i + &#039;&quot;&gt;&lt;\/a&gt;&#039; + hs.eq(i).html());\r\n&nbsp; &nbsp; &nbsp; &nbsp; }\r\n&nbsp; &nbsp; }\r\n&nbsp; &nbsp; while (ol_cnt &gt; 0) {\r\n&nbsp; &nbsp; &nbsp; &nbsp; html += &#039;&lt;\/ol&gt;&#039;;\r\n&nbsp; &nbsp; &nbsp; &nbsp; ol_cnt--;\r\n&nbsp; &nbsp; }\r\n&nbsp; &nbsp; html += &#039;&lt;\/ol&gt;&lt;\/div&gt;&#039;;\r\n&nbsp; &nbsp; html += &#039;&lt;div style=&quot;clear:both&quot;&gt;&lt;br&gt;&lt;\/div&gt;&#039;;\r\n&nbsp; &nbsp; $(html).insertBefore($(&#039;#article&#039;));\r\n}\r\n\r\nfunction openct(e) {\r\n&nbsp; &nbsp; if (e.innerHTML == &#039;[+]&#039;) {\r\n&nbsp; &nbsp; &nbsp; &nbsp; $(e).attr(&#039;title&#039;, &#039;\u6536\u8d77&#039;).html(&#039;[-]&#039;).parent().next().show();\r\n&nbsp; &nbsp; } else {\r\n&nbsp; &nbsp; &nbsp; &nbsp; $(e).attr(&#039;title&#039;, &#039;\u5c55\u5f00&#039;).html(&#039;[+]&#039;).parent().next().hide();\r\n&nbsp; &nbsp; }\r\n&nbsp; &nbsp; e.blur();\r\n&nbsp; &nbsp; return false;\r\n}<\/pre>\n<p>\n\t<span style=\"font-size:16px\"><span style=\"font-family:comic sans ms,cursive\">\u611f\u5174\u8da3\u7684\u7f51\u9875\uff0c\u53ef\u4ee5\u5236\u4f5c\u6210\u63d2\u4ef6\uff0c\u653e\u5230github\u4e0a\uff01<\/span><\/span>\n<\/p>\n<p>\n\t<strong><span style=\"font-size: 16px;font-family: 'comic sans ms', cursive;line-height: 1.6em\">\u7248\u6743\u58f0\u660e\uff1a\u672c\u6587\u4e3a\u535a\u4e3b\u539f\u521b\u6587\u7ae0\uff0c\u672a\u7ecf\u535a\u4e3b\u5141\u8bb8\u4e0d\u5f97\u8f6c\u8f7d\u3002<\/span><\/strong><\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=586\">\u8be6\u89e3\u5982\u4f55\u5b9e\u73b0\u535a\u6587\u4e2d\u81ea\u52a8\u751f\u6210\u6587\u7ae0\u76ee\u5f55\u7684\u505a\u6cd5<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5728CSDN\u5199\u8fc7\u535a\u5ba2\u7684\u4eba\u53ef\u80fd\u4f1a\u4f7f\u7528\u5b83\u63d0\u4f9b\u7684&ldquo;\u6587\u7ae0\u4e2dH1\u5230H6\u6807\u7b7e\u81ea\u52a8\u751f\u6210\u6587\u7ae0\u76ee\u5f55&rdquo;\u8fd9\u4e2a\u529f [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[339,119,341,48,340],"class_list":["post-586","post","type-post","status-publish","format-standard","hentry","category-html5","tag-csdn","tag-html5","tag-olli","tag-web","tag-340"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/586","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=586"}],"version-history":[{"count":2,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/586\/revisions"}],"predecessor-version":[{"id":588,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/586\/revisions\/588"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}