【发布时间】:2017-05-31 08:13:53
【问题描述】:
我有多个带有.expandable-container-mobile 类的按钮。
当我打开按钮时,它会展开。
目前当我打开另一个 div 时,之前打开的 div 不会关闭,但我正在尝试关闭其他部分,下面是我的代码:
$( ".expandable-container-mobile").click(function() {
$(this).children('.mobile-show-section').stop().slideToggle(700);
$(this).not.('.mobile-show-section').stop().slideUp();
});
html代码如下:php代码会生成行和按钮:
<div class="expandable-container-mobile">
<div class="expandable" id="<?php echo strtolower($actual_post_title); ?>-expandable">
<div class="activator">
<div class="section-title" id="<?php echo strtolower($actual_post_title); ?>"><?php echo $actual_post_title; ?></div>
</div>
</div>
<div class="mobile-show-section">
<?php
$args = array(
'sort_order' => 'asc',
'sort_column' => 'post_date',
'child_of' => $id
);
$children = get_pages($args);
$children_ids = array();
if ( ! empty( $children ) )
foreach ( $children as $post )
$children_ids[] = $post->ID;
$arrlength = count($children_ids);
for($x = 0; $x < $arrlength; $x++) {
?>
<a href="<?php echo get_permalink($children_ids[$x]); ?>"><?php echo get_the_title($children_ids[$x]); ?> </a>
<?php
}
?>
</div>
</div>
【问题讨论】:
-
你有一个额外的点
$(this).not.('.mobile-show-section').stop().slideUp();应该是$(this).not('.mobile-show-section').stop().slideUp(); -
能否提供html代码?
-
按钮实际上是 .激活器类
标签: javascript jquery