[英]I want to hide the search bar in my webpage using javascript
I am making a strip menu which turns to hamburger when the page shrinks, am doing it with js, but the search bar is next to it and gets ugly when it toggles, question is how to hide the search bar when the ham-menu is clicked.. I think i can add some lines inside the function to hide it, i have tryed a several options but didn't work我正在制作一个条形菜单,当页面缩小时它会变成汉堡包,我正在使用 js 来做,但是搜索栏在它旁边并且在切换时变得很难看,问题是当火腿菜单是时如何隐藏搜索栏点击..我想我可以在 function 中添加一些行来隐藏它,我尝试了几个选项但没有奏效
const toggleButton = document.getElementsByClassName('toggle-button')[0] const topNav = document.getElementsByClassName('top-nav')[0] const search = document.getElementsByClassName('search-box')[0] toggleButton.addEventListener('click',()=> { topNav.classList.toggle('active') & search.style.display('none') })
const toggleButton = document.getElementsByClassName('toggle-button')[0] const topNav = document.getElementsByClassName('top-nav')[0] const search = document.getElementsByClassName('search-box')[0] toggleButton.addEventListener('click',()=> { topNav.classList.toggle('active') if (search.style.display.= 'none') search.style.display = 'none' else search.style.display = 'block' })
<div class="top-nav"> <input class="search-box"/> </div> <button class="toggle-button">Toggle</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.