Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript “展开”按钮将显示在页面上,尽管在单击按钮本身之前应该将其隐藏 .b1{ 显示:无; 能见度:无; 背景色:蓝色;} 细节 &时代; 方框1_Javascript_Html_Css - Fatal编程技术网

Javascript “展开”按钮将显示在页面上,尽管在单击按钮本身之前应该将其隐藏 .b1{ 显示:无; 能见度:无; 背景色:蓝色;} 细节 &时代; 方框1

Javascript “展开”按钮将显示在页面上,尽管在单击按钮本身之前应该将其隐藏 .b1{ 显示:无; 能见度:无; 背景色:蓝色;} 细节 &时代; 方框1,javascript,html,css,Javascript,Html,Css,一些文本 函数openTab(tabName){ 变量i,x; x=document.getElementsByClassName(“containerTab”); 对于(i=0;i

一些文本

函数openTab(tabName){ 变量i,x; x=document.getElementsByClassName(“containerTab”); 对于(i=0;i 当我进入页面时,我希望我的按钮关闭。我试图将脚本放在标题部分,但还是一样。

以下是我进入时的图片:

当您查找(
#b1
)时,CSS会使用(
.b1

只需更换此部件即可解决问题:

函数openTab(tabName){
变量i,x;
x=document.getElementsByClassName(“containerTab”);
对于(i=0;i
#b1{
显示:无;
能见度:无;
背景颜色:蓝色;
}
详细信息
&时代;
方框1
一些文本

    <head>

         <style>
               .b1{
                display:none;
                visibility: none;
                background-color:blue;}    
         </style>

    </head>        

    <body>
         <button class="offer-btn" onclick="openTab('b1');" type="button">DETAILS</button>

         <div id="b1" class="containerTab" >
           <span onclick="this.parentElement.style.display='none'" class="closebtn">&times;</span>
          <h2>Box 1</h2>
          <p>some text</p>
        </div>

    </body>

    <script>
        function openTab(tabName) {
          var i, x;
          x = document.getElementsByClassName("containerTab");
          for (i = 0; i < x.length; i++) {
             x[i].style.display = "none";
          }
          document.getElementById(tabName).style.display = "block";
        }
    </script>