gpt4 book ai didi

jquery - 找到此类标题,然后在该 div 上方放置一个新词

转载 作者:可可西里 更新时间:2023-11-01 13:07:29 26 4
gpt4 key购买 nike

<HTML>

<HEAD></HEAD>

<BODY BGCOLOR="#ffffff">


<DIV>
<H3 CLASS="Heading-1">First Level Heading</H3>
<DIV>
<H4 CLASS="Heading-2">Second Level Heading</H4>
<DIV>
<H6 CLASS="Heading-3">Third Level Heading</H6>
<P CLASS="Tab-Text-7">Some Text Here</P>
</DIV>


<DIV>
<H6 CLASS="Heading-3">Third Level Heading</H6>
<TABLE>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
Some Cotents Here
</TD>
</TR>
</TABLE>
</DIV>

<DIV>
<H6 CLASS="Heading-3">Third Level Heading</H6>
<TABLE>
<TR>
<TD ROWSPAN="1" COLSPAN="1" class="green1">
Some text goes here
</TD>
</TR>
</TABLE>
</DIV>


<DIV>
<H6 CLASS="Heading-3">Third level Heading</H6>
</DIV>
<DIV>
<H6 CLASS="Heading-4">Fourth Level Heading </H6>
Some Text Goes here
</DIV>


<DIV>
<H4 CLASS="Heading-2">Second Level Heading</H4>
<DIV>
<H6 CLASS="Heading-3">Third Level Heading </H6>
<TABLE>
<TR>
<TD ROWSPAN="1" COLSPAN="1" class="blue1">
SOme text goes here
</TD>
</TR>
</TABLE>
</DIV>
</DIV> <DIV>
<H6 CLASS="Heading-3">Third Level Heading</H6>
Some text goes here
</DIV>
</DIV>
</BODY>

</HTML>

预期输出:-

<HTML>
<HEAD></HEAD>
<BODY BGCOLOR="#ffffff">

xxxxx

<DIV>
<H3 CLASS="Heading-1">First Level Heading</H3>
<DIV>
<H4 CLASS="Heading-2">Second Level Heading</H4>
<DIV>
<H6 CLASS="Heading-3">Third Level Heading</H6>
<P CLASS="Tab-Text-7">Some Text Here</P>
</DIV>

xxxxx

<DIV>
<H6 CLASS="Heading-3">Third Level Heading</H6>
<TABLE>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
Some Cotents Here
</TD>
</TR>
</TABLE>
</DIV>

xxxxx

<DIV>
<H6 CLASS="Heading-3">Third Level Heading</H6>
<TABLE>
<TR>
<TD ROWSPAN="1" COLSPAN="1"class="green1">
Some text goes here
</TD>
</TR>
</TABLE>
</DIV>

xxxxx

<DIV>
<H6 CLASS="Heading-3">Third level Heading</H6>
</DIV>
<DIV>
<H6 CLASS="Heading-4">Fourth Level Heading </H6>
Some Text Goes here
</DIV>

xxxxx

<DIV>
<H4 CLASS="Heading-2">Second Level Heading</H4>
<DIV>
<H6 CLASS="Heading-3">Third Level Heading </H6>
<TABLE>
<TR>
<TD ROWSPAN="1" COLSPAN="1" class="blue1">
SOme text goes here
</TD>
</TR>
</TABLE>
</DIV>

xxxxx

<DIV>
<H6 CLASS="Heading-3">Third Level Heading</H6>
Some text goes here
</DIV>
</BODY>
</HTML>

从上面的代码我想搜索标题并将“XXXXX”放在该标题上方。如果它包含任何子标题(即标题 1 包含标题 2),那么此时它应该将“XXXXX”字放在父标题上方标题而不是子标题。(标题 1 是父标题)

谁能帮帮我。

最佳答案

THIS是你想要的。

1) JQuery 检查文档中的每个标题。
2) 然后搜索父级之前是否有另一个标题。
3) 如果父级之前没有标题,则添加该标题之前的内容。

$(document).find('h1, h2, h3, h4, h5, h6').each(function() {
if ($(this).parent().prev().is('h1, h2, h3, h4, h5, h6') != true) {
$(this).parent().before('<p>xxxxxxx</p>');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<DIV>
<H3 CLASS="Heading-1">First Level Heading</H3>
<DIV>
<H4 CLASS="Heading-2">Second Level Heading</H4>
<DIV>
<H6 CLASS="Heading-3">Third Level Heading</H6>
<P CLASS="Tab-Text-7">Some Text Here</P>
</DIV>


<DIV>
<H6 CLASS="Heading-3">Third Level Heading</H6>
<TABLE>
<TR>
<TD ROWSPAN="1" COLSPAN="1">
Some Cotents Here
</TD>
</TR>
</TABLE>
</DIV>


<div>
<H6 CLASS="Heading-3">Third Level Heading</H6>
<TABLE>
<TR>
<TD ROWSPAN="1" COLSPAN="1"class="green1">
Some text goes here
</TD>
</TR>
</TABLE>
</DIV>


<div>
<H6 CLASS="Heading-3">Third level Heading</H6>
<DIV>
<H6 CLASS="Heading-4">Fourth Level Heading </H6>
Some Text Goes here
</DIV></DIV>


<DIV>
<H4 CLASS="Heading-2">Second Level Heading</H4>
<DIV>
<H6 CLASS="Heading-3">Third Level Heading </H6>
<TABLE>
<TR>
<TD ROWSPAN="1" COLSPAN="1" class="blue1">
SOme text goes here
</TD>
</TR>
</TABLE>
</DIV>


<DIV>
<H6 CLASS="Heading-3">Third Level Heading</H6>
Some text goes here
</DIV>

关于jquery - 找到此类标题,然后在该 div 上方放置一个新词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30659145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com