JS getElementsByClassName(ClassName) 不起作用:什么也没发生

JS getElementsByClassName(ClassName) Not Working : Nothing Happened

本文关键字:什么 不起作用 getElementsByClassName ClassName JS      更新时间:2023-09-26

Code :

(网页)

<html>
  <head>
    <title>Float Image Gallery</title>
  </head>
  <body>
    <button onclick="showAllGalleries();">Show gallery</button>
    <div id="myGallery" class="gallery">
      <div class="gallery-close">
        <img src="http://bit.do/closeicon" onclick="showAds" />
      </div>
    </div>
   </body>
</html>
<style>
.gallery {
  display:none;
  width:100%;
  height:100%;
  left:0;
  bottom:0;
  top:auto;
  right:auto;
  position:fixed;
  background-color:#cccccc;
  opacity:50%;
}
.gallery-close {
  width:auto;
  height:auto;
  margin-top:4px;
  margin-left:4px;
}
<style>
<script>    
function showMyGallery(){
    document.getElementById('myGallery').style.display='inline';
}
function showAllGalleries(){
  var adsArray = document.getElementsByClassName("gallery");
  for (int i; i<adsArray.length; i++){
    adsArray[i].style.display='inline';
  }
}
function hideMyGallery(){
  document.getElementById('myGallery').style.display='inline';
}
</script>

但是,showAllGalleries() 似乎不起作用。
我的 Javascript 代码有什么问题?
尽量避免使用jQuery/语言而不是Javascript来建议答案。
非常感谢您的帮助。

这样做:

for (var i = 0; i<adsArray.length; i++){
    adsArray[i].style.display='inline';
  }

您没有像其他语言那样的intstringfloat和其他数据类型。在javascript中,你所拥有的只是var