gpt4 book ai didi

javascript - 如何在 html 面板中查找标题元素并将事件添加到标题以隐藏 p 标签?

转载 作者:行者123 更新时间:2023-11-30 07:40:33 29 4
gpt4 key购买 nike

我的 JavaScript 有问题。我正在尝试编写一个脚本来查找容器内的所有 header 元素,并将点击事件添加到 header 以隐藏 p 标签。

Javascript 
$(function(){
$("dnn_htmlPan1").find(":header").click(function(){
$("dnn_htmlPan1").find("p").slideToggle("slow");
});
});

HTML

<div id="dnn_htmlPan1" class="htmlPan">
<h2>EXPLORE</h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>

最佳答案

你的 jQuery 选择器是错误的:

# 用于 id:

$("#dnn_htmlPan1").find(":header").click(function(){
$("#dnn_htmlPan1").find("p").slideToggle("slow");
// or
// $(this).parent().find("p").slideToggle("slow");
// or
// $(this).next().slideToggle("slow");
});
});

:header 是正确的:

:header 选择器

Description: Selects all elements that are headers, like h1, h2, h3 and so on.

Read more in documentation

关于javascript - 如何在 html 面板中查找标题元素并将事件添加到标题以隐藏 p 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18212551/

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