欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

询问如何将 div 元素的初始状态设置为隐藏 EN

最编程 2024-06-19 22:37:24
...
代码语言:javascript
复制
element = document.getElementById('toggle');
button = document.getElementById('toggle-button');
function hideAndShow(){
  if(element.style.display == 'none'|| element.style.display == '')    // checks if the display property is set to none or not
  {
    element.style.display = 'Block';  // if set to none then set the display property to block
    button.innerHTML = 'Hide';  // changes the button's text
    
  }
  else{
    element.style.display = 'None';   // otherwise set it to none
    button.innerHTML = 'Show';
  }
}