Javascript 如何使用js、html和css调整此代码,使其具有默认的折叠视图?

Javascript 如何使用js、html和css调整此代码,使其具有默认的折叠视图?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,这是完整的代码,它有js、css和html。我是从一个在线代码片段中得到的,我不擅长Javascript。请帮忙 我在我的主页上摆了这个姿势,占据了空间,如果能把它全部折叠起来就太好了 $(document).on('click','面板标题span.clickable',函数(e){ var$this=$(this); if(!$this.hasClass('panel-collapsed')){ $this.closest('.panel').find('.panel body').sli

这是完整的代码,它有js、css和html。我是从一个在线代码片段中得到的,我不擅长Javascript。请帮忙

我在我的主页上摆了这个姿势,占据了空间,如果能把它全部折叠起来就太好了

$(document).on('click','面板标题span.clickable',函数(e){
var$this=$(this);
if(!$this.hasClass('panel-collapsed')){
$this.closest('.panel').find('.panel body').slideUp();
$this.addClass('panel-collapsed');
$this.find('i').removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
}否则{
$this.closest('.panel').find('.panel body').slideDown();
$this.removeClass('panel-collapsed');
$this.find('i').removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
}
})
.row{
边缘顶端:40px;
填充:0 10px;
}
.可点击{
光标:指针;
}
.面板标题跨度{
利润上限:-20px;
字体大小:15px;
}

小组1
面板内容
小组2
面板内容
小组3
面板内容
小组4
面板内容
  • 将此添加到css:
    。关闭此面板{display:none;}

  • 关闭此面板
    类添加到
    面板主体
    分区

  • 将折叠的
    面板添加到可单击的
    范围中

  • 将图标从
    字形图标字形图标向上
    更改为
    字形图标字形图标向下

  • $(document).on('click','面板标题span.clickable',函数(e){
    var$this=$(this);
    if(!$this.hasClass('panel-collapsed')){
    $this.closest('.panel').find('.panel body').slideUp();
    $this.addClass('panel-collapsed');
    $this.find('i').removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
    }否则{
    $this.closest('.panel').find('.panel body').slideDown();
    $this.removeClass('panel-collapsed');
    $this.find('i').removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
    }
    })
    .row{
    边缘顶端:40px;
    填充:0 10px;
    }
    .可点击{
    光标:指针;
    }
    .面板标题跨度{
    利润上限:-20px;
    字体大小:15px;
    }
    .关闭此面板{
    显示:无;
    }
    
    小组2
    面板内容
    
  • 将此添加到css:
    。关闭此面板{display:none;}

  • 关闭此面板
    类添加到
    面板主体
    分区

  • 将折叠的
    面板添加到可单击的
    范围中

  • 将图标从
    字形图标字形图标向上
    更改为
    字形图标字形图标向下

  • $(document).on('click','面板标题span.clickable',函数(e){
    var$this=$(this);
    if(!$this.hasClass('panel-collapsed')){
    $this.closest('.panel').find('.panel body').slideUp();
    $this.addClass('panel-collapsed');
    $this.find('i').removeClass('glyphicon-chevron-up').addClass('glyphicon-chevron-down');
    }否则{
    $this.closest('.panel').find('.panel body').slideDown();
    $this.removeClass('panel-collapsed');
    $this.find('i').removeClass('glyphicon-chevron-down').addClass('glyphicon-chevron-up');
    }
    })
    .row{
    边缘顶端:40px;
    填充:0 10px;
    }
    .可点击{
    光标:指针;
    }
    .面板标题跨度{
    利润上限:-20px;
    字体大小:15px;
    }
    .关闭此面板{
    显示:无;
    }
    
    小组2
    面板内容
    
    在脚本的末尾抛出这个
    $(文档).ready(函数(){$('.panel heading span.clickable').closest('.panel').find('.panel body').slideDown();})谢谢你的回复,但它不起作用。我实际上没有运行它,或者你的代码我只是在猜测。如果你让你的代码成为可运行的,或者在编辑问题上使用代码编辑器,这样我们就可以看到你的意思,这将使调试变得更容易。我是这个世界的新手,让我试试看是否可以用更好的方式来表达。对不起,请跟我打。在脚本
    $(文档)的末尾扔这个。准备(函数(){$('.panel heading span.clickable')。最近('.panel')。查找('.panel body')。slideDown();})谢谢你的回复,但它不起作用。我实际上没有运行它,或者你的代码我只是在猜测。如果你让你的代码成为可运行的,或者在编辑问题上使用代码编辑器,这样我们就可以看到你的意思,这将使调试变得更容易。我是这个世界的新手,让我试试看是否可以用更好的方式来表达。对不起,请跟我打。