1
<script language="javascript"> 
        function switchdiv() {
       var e = document.getElementById().id;
       if(e == 'Streambtn')
          document.getElementById('Stream').style.display = "block";
       else
          document.getElementById('Stream').style.display = "none";
    }
</script>

Hello,

Here is my problem. When I click, nothing happen...

I hope you can help me.

Thank you

Edit :

Thank you for your answer zzlalani but it unfortunately does not work.

Here is the final code, hoping you'll help me to find a way to fix the problem.

   <div align="center">
    <input type="button" class="btn" name="Stream" value="Stream"  style="padding: 10px 20px 10px 20px; border: 0px; font-family: Play, sans-serif; font-weight: bold" onClick="switchdiv("Streambtn")"/>
    <input type="button" class="btn" name="Youtube" value="Youtube"  style="padding: 10px 20px 10px 20px; border: 0px; font-family: Play, sans-serif; font-weight: bold" onClick="switchdiv("Youtubebtn")"/>
    <input type="button" class="btn" name="LoL" value="League Of Legends"  style="padding: 10px 20px 10px 20px; border: 0px; font-family: Play, sans-serif; font-weight: bold" onClick="switchdiv("LoLbtn")"/>
    </div>
    <script language="javascript"> 
        function switchdiv(e) {
           if(e == 'Streambtn')
              document.getElementById('Stream').style.display = "block";
           else
              document.getElementById('Stream').style.display = "none";
        }
           if(e == 'Youtubebtn')
              document.getElementById('Youtube').style.display = "block";
           else
              document.getElementById('Youtube').style.display = "none";
        }
           if(e == 'LoLbtn')
              document.getElementById('LoL').style.display = "block";
           else
              document.getElementById('LoL').style.display = "none";
        }
    </script>
    <div align="center" id="Stream" hidden>
    <p>a</p>
    </div>
    <div align="center" id="Youtube" hidden>
    <p>b</p>
    </div>
    <div align="center" id="LoL" hidden>
    <p>c</p>
    </div>
4

1 回答 1

1

假设您有一个可以调用switchdiv的按钮click

<input type='button' onClick='switchdiv("Streambtn");' value='Stream!'>
<input type='button' onClick='switchdiv("nonStreambtn");' value='Non Stream!'>

然后它会像这样

<script language="javascript"> 
    function switchdiv(e) {
       if(e == 'Streambtn')
          document.getElementById('Stream').style.display = "block";
       else
          document.getElementById('Stream').style.display = "none";
    }
</script>

你代码中的问题是你没有得到任何价值..以这种方式检查它

var e = document.getElementById().id;
console.log(e);

在浏览器的控制台中,您可以看到会以红色显示一些奇怪的错误

于 2013-10-10T19:56:02.313 回答