我的档案中有一个简单的手风琴菜单,第一个菜单项总是打开的,但是如何修改JS,使所有的菜单项都在页面上关闭?URL为http://helloarchie.blue/archives
JS
function openFirstPanel(){
$('.accordion > dt:first-child').next().addClass('active').slideDown();
}
(function($) {
var allPanels = $('.accordion > dd').hide();
openFirstPanel();
$('.accordion > dt > a').click(function() {
$this = $(this);
$target = $this.parent().next();
if($target.hasClass('active')){
$target.removeClass('active').slideUp();
}else{
allPanels.removeClass('active').slideUp();
$target.addClass('active').slideDown();
}
return false;
});发布于 2015-04-14 14:01:53
删除openFirstPanel()函数和函数调用。
所以你明白了:
(function($) {
var allPanels = $('.accordion > dd').hide();
$('.accordion > dt > a').click(function() {
$this = $(this);
$target = $this.parent().next();
if($target.hasClass('active')){
$target.removeClass('active').slideUp();
}else{
allPanels.removeClass('active').slideUp();
$target.addClass('active').slideDown();
}
return false;
});发布于 2015-04-14 13:51:24
将活动设置为false将折叠所有面板。这要求可折叠选项为true。http://api.jqueryui.com/accordion/
$('.accordion').accordion({
active: false,
collapsible: true
});https://stackoverflow.com/questions/29629164
复制相似问题