gpt4 book ai didi

javascript - insertAfter() 中断点击事件

转载 作者:行者123 更新时间:2023-11-28 15:24:19 25 4
gpt4 key购买 nike

我有以下标记,由 3 个内容 block 组成,每个内容 block 包含一个标题和一些内容:

<div class="feed-panels-expanding">
<div class="feed">

<section>

<h2><a href="#">Heading One</a></h2>
<p>Ut in nulla enim. Phasellus molestie magna non est bibendum non venenatis nisl tempor. Suspendisse dictum feugiat nisl ut dapibus. Mauris iaculis porttitor posuere. Praesent id metus massa, ut blandit odio. Proin.</p>

<div class="content">
<p>Duis aliquet egestas purus in blandit. Curabitur vulputate, ligula lacinia scelerisque tempor.</p>
<p>Lacus lacus ornare ante, ac egestas est urna sit amet arcu. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed molestie augue sit amet leo consequat posuere. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;</p>
<p>Proin vel ante a orci tempus eleifend ut et magna. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus luctus urna sed urna ultricies ac tempor dui sagittis.</p>
</div>

</section>

<section>

<h2><a href="#">Heading Two</a></h2>
<p>Ut in nulla enim. Phasellus molestie magna non est bibendum non venenatis nisl tempor. Suspendisse dictum feugiat nisl ut dapibus. Mauris iaculis porttitor posuere. Praesent id metus massa, ut blandit odio. Proin.</p>

<div class="content">
<p>Duis aliquet egestas purus in blandit. Curabitur vulputate, ligula lacinia scelerisque tempor.</p>
<p>Lacus lacus ornare ante, ac egestas est urna sit amet arcu. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed molestie augue sit amet leo consequat posuere. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;</p>
<p>Proin vel ante a orci tempus eleifend ut et magna. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus luctus urna sed urna ultricies ac tempor dui sagittis.</p>
</div>

</section>

<section>

<h2><a href="#">Heading Three</a></h2>
<p>Ut in nulla enim. Phasellus molestie magna non est bibendum non venenatis nisl tempor. Suspendisse dictum feugiat nisl ut dapibus. Mauris iaculis porttitor posuere. Praesent id metus massa, ut blandit odio. Proin.</p>

<div class="content">
<p>Duis aliquet egestas purus in blandit. Curabitur vulputate, ligula lacinia scelerisque tempor.</p>
<p>Lacus lacus ornare ante, ac egestas est urna sit amet arcu. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed molestie augue sit amet leo consequat posuere. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae;</p>
<p>Proin vel ante a orci tempus eleifend ut et magna. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus luctus urna sed urna ultricies ac tempor dui sagittis.</p>
</div>

</section>

</div>
</div>

我希望单击每个标题可以展开/关闭下面的内容。

我正在尝试获取它,以便 jQuery 脚本负责隐藏除第一段之外的所有内容。为此,它需要将第一段移至 .content 之外。然后隐藏 .content

// feed-panels-expanding
$('.feed-panels-expanding section').each(function() {

$(this).find('h2 a').click(function() {
$(this).parent().next('.content').slideToggle(250);
return false;
});

$(this).find('.content p:first').insertAfter($(this).find('h2'));
$(this).find('.content').hide();

});

但是,脚本确实不喜欢我移动每个内容 block 中的第一个 p 元素。如果我删除该行,则脚本可以正常工作,并且当单击相关标题时所有面板都会展开/收缩。

但是有了这行代码,脚本什么也没做。当我单击标题时,我可以弹出一个 alert 语句,但它只是忽略 .content 元素

最佳答案

next() 查找您选择的元素之后的下一个元素。它不再是 content 元素。下一个元素是您刚刚插入的段落。

$(this).parent().siblings('.content').slideToggle(250);

关于javascript - insertAfter() 中断点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29777320/

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