gpt4 book ai didi

jquery - 除第 1 段外的所有段落环绕 Div

转载 作者:太空宇宙 更新时间:2023-11-04 08:08:56 24 4
gpt4 key购买 nike

无法让它正常工作,所以它适用于每个帖子。

https://jsfiddle.net/haymanpl/htuczx5q/

<p>This is an example of a WordPress post, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many posts as you like in order to share with your readers what is on your mind.</p>

<div class="text">

<p>This is an example of a WordPress post, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many posts as you like in order to share with your readers what is on your mind.</p>

这是 WordPress 帖子的示例,您可以编辑它以放置有关您自己或您网站的信息,以便读者知道您来自哪里。您可以创建任意数量的帖子,以便与读者分享您的想法。

 </div>

$( "p:first-child" ).after(function() {

return '<div class="text">';

});

这有效,但它添加了我不想要的结束 div 标记,因为我需要使用 last-child 添加它。

   $('p:first-child').after( $('<div class="text">') );

我试图将多个段落包装在一个 div 中,但不包括第一段。我需要在第 1 段之后插入,然后在最后一段之后插入结尾。

最佳答案

给您一个解决方案 https://jsfiddle.net/htuczx5q/3/

$('p').not('p:first').wrap('<span class="text" />')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p>This is an example of a WordPress post, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many posts as you like in order to share with your readers what is on your mind.</p>


<p>This is an example of a WordPress post, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many posts as you like in order to share with your readers what is on your mind.</p>

我用过 jQuery wrap .它将包装所有 paragraph除了 first paragraph .

要定位特定的帖子(段落),可以通过三种方式完成:

类名
$('p.className').not('p:first').wrap('<span class="text" />');

身份证
$('p#id').not('p:first').wrap('<span class="text" />');

数据属性
$('p[data-attr="post1"]').not('p:first').wrap('<span class="text" />');

希望对您有所帮助。

关于jquery - 除第 1 段外的所有段落环绕 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46416467/

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