引导手风琴折叠按钮
Bootstrap accordion collapse button
我正在尝试创建一个带有内部按钮的引导手风琴,该按钮将折叠当前手风琴段并打开下一个,这由于某种原因不起作用。
HTML:<div ng-controller="AccordionDemoCtrl">
<accordion>
<accordion-group id="firstpanel" heading="Static Header 1" is-open="status.isFirstOpen">
<span id="span1">This content is straight in the template.</span><br>
<button id="nextpanel">Next</button>
</accordion-group>
<accordion-group heading="Static Header 2">
<span id="span1">This content is straight in the template.</span>
</accordion-group>
</accordion>
</div>
JAVASCRIPT: angular.module('plunker', ['ui.bootstrap']);
function AccordionDemoCtrl($scope) {
$scope.status = {
isFirstOpen: true,
isFirstDisabled: false
};
$("#nextpanel").on("click", function() {
$(firstpanel).click();
});
}
我在这里做了一个plunker的例子:
不能在控制器构造函数中使用jquery选择器。在那个阶段,像#nextpanel
这样的DOM元素甚至不在DOM树中,所以$("#nextpanel")
本质上是一个空数组。
我建议你完全忘记jquery。使用jquery的唯一情况是,当你需要使用一个你已经熟悉的插件(比如日历)时。在任何情况下,jquery代码(带有$()
的代码)应该严格地驻留在包装插件的指令的link函数中。
MVC的方式,是有一个"模型"(JS对象)驱动UI。Angular会用它的魔力让这两个脚本保持同步。
存储打开的手风琴的模型可以是一个布尔值数组:
$scope.status = [true, false, false, false];
打开下一个手风琴只是找到打开的那个,并将下一个设置为true(或绕到第一个)。
$scope.next = function() {
var indx = $scope.status.indexOf(true);
$scope.status[(++indx) % $scope.status.length] = true;
};
accordion组件将确保在任何给定时间只有一个是true
。
<accordion>
<accordion-group heading="Static Header 1" is-open="status[0]">
<span>This content is straight in the template.</span><br>
<button ng-click="next()">Next</button>
</accordion-group>
<accordion-group heading="Static Header 2" is-open="status[1]">
<span>This content is straight in the template.</span><br>
<button ng-click="next()">Next</button>
</accordion-group>
<accordion-group heading="Static Header 3" is-open="status[2]">
<span>This content is straight in the template.</span><br>
<button ng-click="next()">Next</button>
</accordion-group>
<accordion-group heading="Static Header 4" is-open="status[3]">
<span>This content is straight in the template.</span><br>
<button ng-click="next()">Start over</button>
</accordion-group>
</accordion>
这是固定活塞
相关文章:
- Bootstrap折叠按钮不适用于android
- 每行的折叠按钮
- jQuery sidebartToggler需要使用按钮展开和折叠
- 折叠导航按钮不适用于twitter引导程序设计的移动设备
- 触发Bootstrap's不使用按钮或A标记进行折叠
- 添加一个“;关闭“;按钮展开折叠段落
- 引导两个响应菜单-单击另一个菜单按钮时折叠一个菜单
- 如何防止按钮单击折叠窗格
- HTML 单选按钮折叠和滑动
- Jquerymobile - 按钮展开/折叠所有
- 如何让可折叠按钮仅针对移动设备显示
- 在引导手风琴上, 有没有办法在折叠时向标题添加固定的保存按钮.
- 使用jQuery可折叠列表 - 如何更新展开/折叠全部按钮
- 按钮以展开和折叠所有在jQuery手风琴上
- 当使用 Javascript 单击按钮或图像时,表列折叠
- jQuery 折叠按钮不加载远程内容
- 需要消失的其他按钮折叠列表,一旦一个按钮被按下
- 如何使按钮折叠后设置为隐藏在asp.net中的javascript
- 带有按钮折叠问题的引导面板
- 切换按钮折叠在引导程序的引导程序导航栏中不起作用