我试图从使用H1的文档中获取所有节标题元素( H2、H3、H4、H5、H6)的数量,例如:
$headerCount=$xpath->query("count(//*[self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6])");
我用这个例子在上测试了上面的查询,结果得到了'6‘:
<h2>Header 1</h2>
<h2>Header 2</h2>
<h3>Header 2.1</h3>
<
我在寻找一个Jquery自动内容表生成器。尝试了不同的方法,直到我找到了这一个,它工作得很好。
$(document).ready(function() {
$(tocList).empty();
var prevH2Item = null;
var prevH2List = null;
var index = 0;
$("h2, h3").each(function() {
假设我在页面上有一些这样的标题 <h1 class="head-1"> Title 1 </h1>
<h2 class="head-2"> title 2 </h2>
<h3 class="head-3"> title 2.1 </h3>
<h3 class="head-3"> title 2.2 </h3>
<h2 class="head-2"> title
假设我有这样的内容:
<div class="entry">
<p>I want to display <br /><h2>heading level elements like this</h2>
<p> as inline elements on the same line with the text that preceded them as well as...</p>
<p>the text that<br />
<h3>(another headi