如何使手风琴面板可单击,而不仅仅是文本

时间:2018-06-29 13:50:23

标签: html accordion

如果这是一个愚蠢的问题,请先抱歉,但是我一直在尝试各种不同的事情,没有什么是对的。 对于所有这些,我还比较陌生,正在研究其他人的代码。

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

这是代码。

<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>

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

enter image description here

1 个答案:

答案 0 :(得分:0)

<!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复制了这段代码,所以不要给我任何荣誉