Javascript - 手风琴:如何在任何给定时间只打开一个项目
Javascript - Accordion: how to let only one item to be open at any given time
我想编写一个脚本,允许只有一个项在任何给定时间打开,强制其他 关闭。
我该怎么做?
这是我的起点:
var myApp = new Framework7();
var $$ = Dom7;
$$('.accordion-item').on('opened', function () {
myApp.alert('Accordion item opened');
});
$$('.accordion-item').on('closed', function (e) {
myApp.alert('Accordion item closed');
});
在 Framework7 手风琴列表中总是只有一个打开,另一个关闭。
<!-- List View -->
<div class="content-block-title">List View Accordion</div>
<!-- add "accordion-list" class -->
<div class="list-block accordion-list">
<ul>
<li class="accordion-item"><a href="#" class="item-content item-link">
<div class="item-inner">
<div class="item-title">Item 1</div>
</div></a>
<div class="accordion-item-content">
<div class="content-block">
<p>Item 1 content. Lorem ipsum dolor sit amet...</p>
</div>
</div>
</li>
<li class="accordion-item"><a href="#" class="item-content item-link">
<div class="item-inner">
<div class="item-title">Item 2</div>
</div></a>
<div class="accordion-item-content">
<div class="content-block">
<p>Item 2 content. Lorem ipsum dolor sit amet...</p>
</div>
</div>
</li>
...
</ul>
</div>
我想编写一个脚本,允许只有一个项在任何给定时间打开,强制其他 关闭。
我该怎么做?
这是我的起点:
var myApp = new Framework7();
var $$ = Dom7;
$$('.accordion-item').on('opened', function () {
myApp.alert('Accordion item opened');
});
$$('.accordion-item').on('closed', function (e) {
myApp.alert('Accordion item closed');
});
在 Framework7 手风琴列表中总是只有一个打开,另一个关闭。
<!-- List View -->
<div class="content-block-title">List View Accordion</div>
<!-- add "accordion-list" class -->
<div class="list-block accordion-list">
<ul>
<li class="accordion-item"><a href="#" class="item-content item-link">
<div class="item-inner">
<div class="item-title">Item 1</div>
</div></a>
<div class="accordion-item-content">
<div class="content-block">
<p>Item 1 content. Lorem ipsum dolor sit amet...</p>
</div>
</div>
</li>
<li class="accordion-item"><a href="#" class="item-content item-link">
<div class="item-inner">
<div class="item-title">Item 2</div>
</div></a>
<div class="accordion-item-content">
<div class="content-block">
<p>Item 2 content. Lorem ipsum dolor sit amet...</p>
</div>
</div>
</li>
...
</ul>
</div>