gpt4 book ai didi

javascript - jQuery 切换根本不触发

转载 作者:行者123 更新时间:2023-11-30 23:56:28 25 4
gpt4 key购买 nike

DEMO

为什么 jquery 切换没有触发任何内容来折叠描述?我尝试移动标题中的 CDNJS 链接 - 没有任何内容,向下移动到正文标记的内部和外部,没有任何效果。它仅适用于 JSFIDDLE

在我决定发布此内容之前,我研究并发现了一些类似的问题,但仍然对我不起作用。我在这里错过了什么吗?

HTML -

<div class="parent-container">
<ul class="faq">
<li>
<h3 class="question">SVRS Header 1
<div class="plus-minus-toggle collapsed"></div>
</h3>
<div class="answer">Donec vitae tellus risus. Aenean sed fermentum risus. Phasellus venenatis <br><br>
ultricies dignissim. Nunc ante lectus, accumsan non porta at. Donec vitae tellus risus. Aenean sed
fermentum risus. Phasellus venenatis ultricies dignissim.</div>
</li>
<li>
<h3 class="question">SVRS Header 2
<div class="plus-minus-toggle collapsed"></div>
</h3>
<div class="answer">onec vitae tellus risus. Aenean sed fermentum risus. Phasellus venenatis <br><br>
ultricies dignissim. Nunc ante lectus, accumsan non porta at. Donec vitae tellus risus. Aenean sed
fermentum risus. Phasellus venenatis ultricies dignissim.</div>
</li>
<li>
<h3 class="question">SVRS Header 3
<div class="plus-minus-toggle collapsed"></div>
</h3>
<div class="answer">onec vitae tellus risus. Aenean sed fermentum risus. Phasellus venenatis <br><br>
ultricies dignissim. Nunc ante lectus, accumsan non porta at. Donec vitae tellus risus. Aenean sed
fermentum risus. Phasellus venenatis ultricies dignissim.</div>
</li>
</ul>
</div>

JS 切换 -

$('.faq li .question').click(function () {
$(this).find('.plus-minus-toggle').toggleClass('collapsed');
$(this).parent().toggleClass('active');
});

CSS

.parent-container {
padding: 0 20px 0 20px;
max-width: 800px;
width: 100%;
}

.faq {
list-style: none;
padding-left: 40px;
padding-right: 20px;
}

.faq li.active .answer {
max-height: 275px !important;
transition: max-height 0.5s ease, padding-bottom 0.5s ease;
}

.faq li.active .question {
color: #808080;
transition: color 0.5s ease;
}

.faq .answer {
color: #090909;
font-family: serif;
font-size: 16px;
max-height: 0;
overflow: hidden;
transition: max-height 0.5s ease, padding-bottom 0.5s ease;
}

.faq .plus-minus-toggle {
cursor: pointer;
height: 20px;
position: absolute;
width: 20px;
left: -40px;
top: 50%;
z-index: 2;
}

.faq .plus-minus-toggle:before, .faq .plus-minus-toggle:after {
background: #000;
content: "";
height: 5px;
left: 0;
position: absolute;
top: 0;
width: 20px;
transition: transform 500ms ease;
}

.faq .plus-minus-toggle:after {
transform-origin: center;
}

.faq .plus-minus-toggle.collapsed:after {
transform: rotate(90deg);
}

.faq .plus-minus-toggle.collapsed:before {
transform: rotate(180deg);
}

.faq .question {
color: #090909;
font-family: sans-serif;
font-size: 20px;
font-weight: 800;
text-transform: uppercase;
position: relative;
cursor: pointer;
padding: 5px 0;
transition: color 0.5s ease;
}

@media screen and (max-width: 767px) {
.faq .question {
font-size: 18px;
}

}

最佳答案

可以通过控制台得到答案:Uncaught ReferenceError: $ is not Define

出现此错误的原因是您在加载 jQuery 库之前使用了 jQuery 语法/函数。

最简单的可视化是这样的:

console.log(a);
let a = "test";

要运行您的网站,您应该始终将 jQuery 脚本加载标记放在自定义编码内容之前的头部部分。

您的网站应如下所示:

<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

<script>
//do jQuery here
</script>
</head>

关于javascript - jQuery 切换根本不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61018887/

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