【问题标题】:How can I make an accordion panel clickable, not just text如何使手风琴面板可点击,而不仅仅是文本
【发布时间】:2018-06-29 13:50:23
【问题描述】:

如果这是一个愚蠢的问题,请提前抱歉,但我一直在尝试很多不同的东西,但没有什么是安静的。 我对所有这一切也相对较新,并且正在处理其他人的代码。

我正在尝试使整个面板可点击,而不仅仅是手风琴的文本。

这是代码。

<div uib-accordion-group is-open="topic6.open">
    <uib-accordion-heading>
        <strong>
            <span id="help" style="font-size:16px;text-decoration:none;cursor:pointer;)" translate="help">
                <i class="pull-right glyphicon" ng-class="{'glyphicon-chevron-up': topic6.open, 'glyphicon-chevron-down': !topic6.open}"  style="font-size:21px;"></i>
            </span>
        </strong>
    </uib-accordion-heading>
    <span translate="help_aboutmessage1"></span>
    <br>
</div>

这就是它的样子。如您所见,目前可点击的只有“帮助”文本。

【问题讨论】:

  • 读者:这个问题似乎与 Bootstrap 的 Angular 指令有关。

标签: html accordion


【解决方案1】:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.accordion {
    background-color: #eee;
    color: #444;
    cursor: pointer;
    padding: 18px;
    width: 100%;
    border: none;
    text-align: left;
    outline: none;
    font-size: 15px;
    transition: 0.4s;
}

.active, .accordion:hover {
    background-color: #ccc; 
}

.panel {
    padding: 0 18px;
    display: none;
    background-color: white;
    overflow: hidden;
}
</style>
</head>
<body>

<h2>Accordion</h2>

<button class="accordion">Section 1</button>
<div class="panel">
  <p>Panel #1</p>
</div>

<button class="accordion">Section 2</button>
<div class="panel">
  <p>Panel #2.</p>
</div>

<button class="accordion">Section 3</button>
<div class="panel">
  <p>Panel #3</p>
</div>

<script>
var acc = document.getElementsByClassName("accordion");
var i;

for (i = 0; i < acc.length; i++) {
    acc[i].addEventListener("click", function() {
        this.classList.toggle("active");
        var panel = this.nextElementSibling;
        if (panel.style.display === "block") {
            panel.style.display = "none";
        } else {
            panel.style.display = "block";
        }
    });
}
</script>

</body>
</html>

顺便说一句,我只是从 W3schools 复制了这段代码,所以不要给我任何信用

【讨论】:

    猜你喜欢
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 2014-04-03
    • 2021-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-20
    相关资源
    最近更新 更多