作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 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.
关于javascript - 如何在 html 面板中查找标题元素并将事件添加到标题以隐藏 p 标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18212551/
我是一名优秀的程序员,十分优秀!