简体   繁体   English

我想添加一个手风琴,但它没有打开

[英]I am trying to add an accordion but its not opening

Accordion is not opening on clicking upon the button.单击按钮时,手风琴不会打开。

please help.请帮忙。

many thanks!非常感谢!

please find code written below: please find code written below: please find code written below: please find code written below: please find code written below: please find code written below: please find code written below: please find code written below: please find code written below: please find code written below: please find code written below: please find code written below:请找到下面写的代码: 请找到下面写的代码: 请找到下面写的代码: 请找到下面写的代码: 请找到下面写的代码: 请找到下面写的代码: 请找到下面写的代码: 请找到下面写的代码: 请找到下面写的代码: 请找到下面写的代码: 请找到下面写的代码: 请找到下面写的代码:

please find code written below:请找到下面写的代码:

 < script > document.querySelectorAll("accordion__button").forEach(button => { button.addEventListener("click", () => { const accordionContent = button.nextElementSibling; button.classList.toggle("accordion__button--active"); if (button.classList.contains("accordion__button--active")) { accordionContent.style.maxHeight = accordionContent.scrollHeight + 'px'; } else { accordionContent.style.maxHeight = 0; } }); }); </script>
 .accordion__button { display: block; width: 100%; padding: 15px; border: none; outline: none; cursor: pointer; background: #333333; color: #ffffff; text-align: left; transition: background 0.2s; } .accordion__button::after { content: '\\25be'; float: right; transform: scale(1.5); } .accordion__button--active { background: #555555; } .accordion__button--active::after { content: '\\25be'; } .accordion__content { overflow: hidden; max-height: 0; transition: max-height 0.2s; padding: 0 15px; font-family: sans-serif; background: #eeeeee; }
 <div class="accordion"> <button type="button" class="accordion__button">FUP Plans</button> <div class="accordion__content"> <p>"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia </p> </div> </div>

 <script> document.querySelectorAll("accordion__button").forEach(button => { button.addEventListener("click", () => { const accordionContent = button.nextElementSibling; button.classList.toggle("accordion__button--active"); if (button.classList.contains("accordion__button--active")) { accordionContent.style.maxHeight = accordionContent.scrollHeight + 'px'; } else { accordionContent.style.maxHeight = 0; } }); }); </script>
 .accordion__button { display: block; width: 100%; padding: 15px; border: none; outline: none; cursor: pointer; background: #333333; color: #ffffff; text-align: left; transition: background 0.2s; } .accordion__button::after { content: '\\25be'; float: right; transform: scale(1.5); } .accordion__button--active { background: #555555; } .accordion__button--active::after { content: '\\25be'; } .accordion__content { overflow: hidden; max-height: 0; transition: max-height 0.2s; padding: 0 15px; font-family: sans-serif; background: #eeeeee; }
 <div class="accordion"> <button type="button" class="accordion__button">FUP Plans</button> <div class="accordion__content" > <p>"At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia </p> </div> </div>

enter code here

The problem is with this modified line.问题在于这条修改过的线路。

  document.querySelectorAll(".accordion__button").forEach(button => { ... });

just add the '.'只需添加“。” character to define the classname of the element.字符来定义元素的类名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试使用jQuery选项将类添加到手风琴,但是它不起作用 - I am trying to add a class to accordion using jQuery option, but it does not work 我正在尝试使用 heroku 部署一个简单的 nodejs 应用程序,它已成功部署,但在打开 url 时出错? - I am trying to deploy a simple nodejs app using heroku and its is deployed successfully but giving error on opening the url? 您好我正在尝试使用输入参考添加材料 ui Iconbutton 以上传图像它不起作用 - Hi I am trying to add the material ui Iconbutton with input ref to upload the image its not working 我正在尝试在 React.js 网站中添加路由,但它不起作用 - I am trying to add Routing in a React.js website but not its not working 通过手风琴菜单,我如何确保打开菜单关闭其兄弟姐妹? - With an accordion menu, how can I ensure opening a menu closes its siblings? 为手风琴打开/关闭添加缓动效果 - Add Easing effect to Accordion Opening / Closing 我正在制作手风琴的麻烦 - trouble with accordion I am making 我正在尝试添加关闭功能 - I am trying to add the close function 我正在尝试向 js object 添加一个元素 - I am trying to add an element to a js object 我正在尝试制作公会添加消息 - I am trying to make a guild add message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM