仅在单击右侧符号

时间:2016-04-28 11:33:07

标签: javascript angularjs accordion

如果我点击标题上的任何地方,我想禁用打开手风琴的点击事件。相反,我想只点击最右边的符号.... 如果我点击“保存”按钮,它就会打开..

  <accordion-group is-open="status.open" template-url="accordion-group.html">
        <accordion-heading>
            I can have markup, too! <button type="button">Save</button> <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"></i>
        </accordion-heading>
        This is just some content to illustrate fancy headings.
    </accordion-group>

这里是掠夺者......

link

1 个答案:

答案 0 :(得分:3)

在您修改的html文件中:

  <accordion close-others="oneAtATime">
    <accordion-group style="pointer-events:none !important;" is-open="status.open" template-url="accordion-group.html">
        <accordion-heading style="pointer-events:none !important;">
            I can have markup, too! <button style="pointer-events:none !important;" type="button">Save</button> <i class="pull-right glyphicon" style="pointer-events:auto !important;" ng-class="{'glyphicon-chevron-down': status.open, 'glyphicon-chevron-right': !status.open}"></i>
        </accordion-heading>
        This is just some content to illustrate fancy headings.
    </accordion-group>
  </accordion>

你应该在你不会对鼠标点击事件作出反应的元素上添加css属性:“pointer-events:none!important”,并且只在你的图标指示器上设置“pointer-events:auto!important”。只有在单击箭头图标时才能打开手风琴。这应该有效:)

为了使您的解决方案更加优雅,您可以制作CSS类:

.disable-click-event {
    pointer-events: none !important;
}

.enable-click-event {
    pointer-events: auto !important;
}

还有一个选项可以防止事件冒泡($ event.stopPropagation())但在这种情况下我不知道究竟在哪里调用事件,因此需要进行严格的调查才能找到它。

还有一个提示:如果有任何问题可以通过CSS而不是JS来解决它完全值得这么做:) JavaScript事件不是那么容易调试,因此CSS修复将比使用事件冒泡的脏bug快得多。我可以建议你使用简单的CSS解决方案,并且有良心:)欢呼