javascript崩溃不起作用

javascript崩溃不起作用,javascript,jquery,html,css,Javascript,Jquery,Html,Css,大家好,我的社区, 我得到了faq崩溃的代码,但它不起作用 HTML javascript <script> //faq toggle stuff $('.togglefaq').click(function(e) { e.preventDefault(); var notthis = $('.active').not(this); notthis.find('.icon-remove ').addClass('icon-plus').removeClass('icon-remov

大家好,我的社区, 我得到了faq崩溃的代码,但它不起作用

HTML

javascript

<script>
//faq toggle stuff 
$('.togglefaq').click(function(e) {
e.preventDefault();
var notthis = $('.active').not(this);
notthis.find('.icon-remove ').addClass('icon-plus').removeClass('icon-remove ');
notthis.toggleClass('active').next('.faqanswer').slideToggle(300);
 $(this).toggleClass('active').next().slideToggle("fast");
$(this).children('i').toggleClass('icon-plus icon-remove ');
});
</script>

//常见问题解答切换内容
$('.togglefaq')。单击(函数(e){
e、 预防默认值();
var notthis=$('.active')。not(this);
notthis.find('.icon-remove').addClass('icon-plus').removeClass('icon-remove');
notthis.toggleClass('active')。next('faqanswer')。slideToggle(300);
$(this.toggleClass('active').next().slideToggle(“fast”);
$(this).children('i').toggleClass('icon-plus-icon-remove');
});
在代码笔上它可以工作


但是,当我将它添加到我的网站时,它并不

您需要将它放入一个
(函数($){…})(jQuery)
jQuery(文档).ready(函数(){…})


您还必须引用jQuery。

是否引用了jQuery?请执行一些基本调试。控制台中出现了什么错误?好的,它工作了sheetcovering.com/sr/examples/backgroundsFixed.html,但我还有一个问题,我的页面是滚动页面为什么当我显示答案时页面冻结,我无法再滚动了?好的,它工作了,但我还有一个问题,我的页面是滚动页面为什么当我显示答案时页面冻结,我不能再滚动了?
/* FAQ COLLAPSE/EXPAND STYLES */
* {
  box-sizing: border-box;
}
body{
  background-color:black;
}
.faqanswer {
    display: none;
    width: 590px;
    padding: 12px 20px 0 30px;
  background-color:white;

}

.faqanswer p {
    font-size: 13px;
    line-height: 17px;  
    padding-bottom: 20px;
  color:#2b2d39;

}


a.active {
    font-weight: bold;
}

.togglefaq {
    text-decoration: none;
    color: #2b2d39;
    font-size: 13px;
    padding: 10px 30px;
    line-height: 20px;
    display: block;
    width: 590px;
    margin-bottom: -1px;
    background-color:white;
}
.icon-plus {
    color: #1c1e2b;
    margin-right: 20px;
    font-size: 20px;
    float:right;
}

.icon-remove {
    color: #1c1e2b;
    font-size: 20px;
    float:right;
}
p {
  margin: 0;
}
<script>
//faq toggle stuff 
$('.togglefaq').click(function(e) {
e.preventDefault();
var notthis = $('.active').not(this);
notthis.find('.icon-remove ').addClass('icon-plus').removeClass('icon-remove ');
notthis.toggleClass('active').next('.faqanswer').slideToggle(300);
 $(this).toggleClass('active').next().slideToggle("fast");
$(this).children('i').toggleClass('icon-plus icon-remove ');
});
</script>
(function ($) {

    $('.togglefaq').click(function(e) {
    e.preventDefault();
    var notthis = $('.active').not(this);
    notthis.find('.icon-remove ').addClass('icon-plus').removeClass('icon-remove ');
    notthis.toggleClass('active').next('.faqanswer').slideToggle(300);
     $(this).toggleClass('active').next().slideToggle("fast");
    $(this).children('i').toggleClass('icon-plus icon-remove ');
    });

})(jQuery);