[英]How can I make an accordion panel clickable, not just text
抱歉,如果这是一个愚蠢的问题,但我一直在尝试各种不同的事情,没有什么是对的。 我对所有这些都还比较陌生,正在研究其他人的代码。
我试图使整个面板都可单击,而不只是使手风琴的文本可用。
这是代码。
<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>
这就是它的样子。 如您所见,当前所有可单击的是“帮助”文本。
<!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复制了此代码,所以不要给我任何荣誉
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.